Installation and Setup

JythonFaq

TableOfContents


Why do I get NoClassDefFoundError when running the installer

Make sure that the class name on the command line doesn't end in .class. Also make sure that the installer actually exists in your current working directory.


Why can't I use "from java import ..." on Windows?"

This problem can occur if you are using Microsoft's VM (i.e. jview.exe) which provides the standard classes in a different format. You need to run the following command in a console window before using Jython:

    clspack -auto


What is "python.path" and "python.prepath" mean in the Jython registry

The key "python.path" in the Jython registry has recently changed. This FAQ entry is intended to clarify registry keys related to sys.path settings.

Before Fri, December 15, 2000- the "python.path" key in the registry file appended the given value to the sys.path list before the (sys.prefix)/lib directory is added. This means for Jython-2.0a1 and before, the above behavior is expected.

Changes committed on December 15, 2000 change the behavior so that the registry's "python.path" key is appended to sys.path after (sys.prefix)/lib directory. This applies to CVS versions and any subsequently released versions of Jython.

This mimics the behavior of the appending that takes place in the autoloaded site.py. Traditionally JPython users have appended the CPython path in this registry key; however, this was unsafe as it then preceded the Jython lib directory. This change eliminates errors associated with appending the CPython lib path in this key.

For those instances where you do intend to add something to the sys.path before (sys.prefix)/lib, there is a new registry key called "python.prepath". This exists only after the 20001215 change date.

Here is the summary of changing sys.path:

Before 20001215:

  1. python.path key appends given path before (sys.prefix)/lib. Do not put the CPython Lib dir in the python.path key unless you precede it with the Jython lib path. (using site.py may be a better choice).
  2. Jython-2.0a1 autoloads site.py (as does Python20) and appends path changes after (sys.prefix)/lib- a better alternative to appending to sys.path.

After 20001215:

  1. python.path key appends given path after (sys.prefix)/lib. Same as autoloaded site.py file.
  2. A new key, "python.prepath", was added to append path's before (sys.prefix)/lib if needed.

If there is confusion about site.py:


Why no command-line history in Jython?

The shells and other tools commonly associated with having a command-line history get this functionality from the C 'readline' package. There is experimental 'readline' classes in Java, and is likely to be in Jython's future. For the current release, there is console.py in the demo directory that adds a simple up/down.

It is not commonly the case that programs look to the shell for this functionality, it is more common that readline is compiled in to the shell (or CPython) you are using which provides this functionality. However, some shells wrap the stdin/out of other programs (Jython). Shell mode in emacs is an excellent example. "rlterm", a shell that comes with the Unix version of Yorick, also does this (i.e. "rlterm jython"). There may be many others do the same so you can supplant the functionality of readline.


Why do I get the error, "can't create package cache dir, '/cachedir/packages'"

An essential optimization in Jython is the caching of Java package information. The caching requires '/cachedir/packages/' in the python.home directory. It is often the case on *nix that users lack sufficient priveledges to create or write to this directory.

Because the problem is merely permissions, something similar to "mkdir cachedir; chmod a+rw cachedir" within Jython's directory should eliminate this error message.

If you are using Windows, the solution is even easier. The value you have set for the "-Dpython.home" in your startup doesn't exist. Either correct the typo or create that directory.


Where's the registry file

Jython's installation includes a file called "registry" that you will find in the root directory of the Jython installation (e.g. /usr/local/jython or c:\jython).

At initialization, Jython searches for the "registry" file in the directory specified by the "python.home" property, or the ".jython" file in the user's home directory.

The "python.home" property is often set in the startup with Java's -D switch. The shell script that starts Jython (jython.bat or jython) demonstrates the use of the -D switch to set the "python.home" property. When embedding Jython, it is often still best to use the -D switch because the -D properties appear in System.getProperties(), which is usually the "preProperties" (first arg) in the static PythonInterpreter.initialize method. With python.home in the preProperties, the interpreter successfully loads preProperties, registry properties, and postProperties (the second arg to initialize) in the correct order.

If you wish to use your home directory, and do not know where your home directory is, don't worry- Jython knows:

 >>> print java.lang.System.getProperty("user.home") 

If you run into complaints about create ".jython", don't worry- Jython can:

 >>> import java, os
 >>> filename = os.path.join(java.lang.System.getProperty("user.home"), ".jython")
 >>> open(filename, "w")


GUI-less installer?

If you do not have a GUI, then add -o dir_to_install_to to the command. Jython will install to the specified directory without bringing up the graphical installer. E.g. to install all modules to a Jython-2.1 subdirectory in the current directory do:

    <java interpreter> jython-21 -o Jython-2.1 demo lib source 


How do I build from the 2.2 alpha release?

Download and unpack the jar file made available as the latest release. If you build straight from the unpacked jar file, you will probably get a Java compilation error indicating package org.python.core doesn't exist. To fix, move the contents of the src/java directory to the base directory the jar was unpacked into.

You will also need CPython 2.2 installed on the same machine, plus other dependencies listed with the release.

---

Jython cannot find your Java class, even though it exists in the class path.

Jython cannot find your Java class, even though it exists in the class path. This shows up as "ImportError: cannot import name xxx" or "AttributeError: java package xxx' has no attribute 'yyy'"

This happens when Jython is installed as a Java extension (i.e. when jython.jar is installed in java\jre\lib\ext\) and your classes are installed in the classpath.

The reason is Java extensions can only see other extensions, not other classes defined in the CLASSPATH or passed in to java using the --classpath option.

There are two ways to fix this:

1) Move your classes to the java\jre\lib\ext directory.

2) Remove jython.jar from the java\jre\lib\ext directory and put jython.jar in the CLASSPATH or use the java --classpath option.

(from the Jython-users mailing list)