Differences between revisions 1 and 16 (spanning 15 versions)
Revision 1 as of 2005-02-07 18:48:43
Size: 5808
Editor: BillDehora
Comment:
Revision 16 as of 2015-04-30 18:18:16
Size: 3088
Editor: JimBaker
Comment: Update to 2.7
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
'''Why do I get NoClassDefFoundError when running the installer''' = Installation and Setup =
Line 3: Line 3:
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. JythonFaq

<<TableOfContents>>


== Command-line support in Jython? ==

Jython 2.5 and 2.7 fully support command-line history using JLine, although there are circumstances in which JLine cannot be loaded. (This is currently the case on cygwin for Jython 2.7.0.)

Jython 2.7 also supports tab completion.
Line 7: Line 16:
== Why do I get the error, "can't create package cache dir, '/cachedir/packages'" ==
Line 8: Line 18:
'''Why can't I use "from java import ..." on Windows?"''' 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.
Line 10: Line 20:
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: Because the problem is merely permissions, something similar to "mkdir cachedir; chmod a+rw cachedir" within Jython's directory should eliminate this error message.
Line 12: Line 22:
{{{
    clspack -auto
}}}
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.
Line 18: Line 27:
'''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).
 1. 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.
 1. 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.

----

'''Where's the registry file'''
== Where's the registry file ==
Line 85: Line 48:
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:
== GUI-less installer? ==
Line 88: Line 50:
{{{ <java interpreter> jython-21 -o Jython-2.1 demo lib source }}} Run

{{{ java -jar jython-installer.jar --help }}}

for full help, including text console and command line installation.

----

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

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 run using java -jar jython.jar. Use the Jython launcher (bin/jython or bin\jython.exe) to ensure that the Jython jar is on the CLASSPATH.

Installation and Setup

JythonFaq

Command-line support in Jython?

Jython 2.5 and 2.7 fully support command-line history using JLine, although there are circumstances in which JLine cannot be loaded. (This is currently the case on cygwin for Jython 2.7.0.)

Jython 2.7 also supports tab completion.


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?

Run

 java -jar jython-installer.jar --help 

for full help, including text console and command line installation.


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

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 run using java -jar jython.jar. Use the Jython launcher (bin/jython or bin\jython.exe) to ensure that the Jython jar is on the CLASSPATH.

JythonFaq/InstallingJython (last edited 2015-04-30 18:18:16 by JimBaker)