Installation and Setup
Installation and Setup
- Why do I get NoClassDefFoundError when running the installer
- Why can't I use "from java import ..." on Windows?"
- What do "python.path" and "python.prepath" mean in the Jython registry?
- Why no command-line history in Jython?
- Why do I get the error, "can't create package cache dir, '/cachedir/packages'"
- Where's the registry file
- GUI-less installer?
- Jython cannot find your Java class, even though it exists in the class path.
- Compiling Jython from source on Ubuntu
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:
What do "python.path" and "python.prepath" mean in the Jython registry?
As of Subversion revision 5043 (August 1, 2008), "python.prepath" no longer has any effect; "python.path" replaces it, reverting to the behavior of Python 2.0a1 and earlier (and CPython). This workaround is no longer necessary because CPython standard library has been included with Jython for some time.
Historical information follows:
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 Jython 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:
- 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).
- 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.
- python.path key appends given path after (sys.prefix)/lib. Same as autoloaded site.py file.
- A new key, "python.prepath", was added to append path's before (sys.prefix)/lib if needed.
If there is confusion about site.py:
- site.py is automatically loaded on normal startup in Python 2.0 and Jython-2.0a1. This used to be user-loaded in Python 1.5.2 and JPython11.
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")
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
Jython cannot find your Java class, even though it exists in the class path.
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)
Compiling Jython from source on Ubuntu
If it complains that Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar, then jython compiler is unable to find the correct java for it's use. You sudo apt-get install sun-java6-jdk and sudo update-alternatives --config java and select the option to Sun Java and ant build should work fine.