How are python.cachedir and the error "*sys-package-mgr*: can't create package cache dir" are related

While starting WLST or for that matter Jython, you might have seen this annoying error message,

*sys-package-mgr*: can’t create package cache dir, ‘/tmp/cachedir/packages’
Traceback (innermost last):
File “<iostream>”, line 12, in ?
ImportError: no module named java

When Jython initializes it scans all the jar files it can find at startup to build the package and class structure available to the JVM. This information is written to files in a directory named ‘cachedir’, WLST chooses your ‘java.io.tmpdir’ to store these files. There is a problem with this approach especially on Unix machines.

Problem:

Most Unix machines are shared across a number of users. Say “user1″ first logs into the machine and fired up ‘java weblogic.WLST’, Jython will create the ‘cachedir’ under ‘/var/tmp/’ and this directory will be owned by ‘user1′. This user will have no problems using WLST. Now ‘user2′ logs in and fires up WLST, this process will try to write to the same directory, ‘/var/tmp/cachedir’ which is now owned by ‘user1′ and henceĀ fails with the above error message.

Solution:

There is a pretty simple and straight forward solution to this problem. Jython supports a System property (python.cachedir) that you can set which will determine the directory where this ‘cachedir’ is created. So in our case to start WLST you will use,

java -Dpython.cachedir=/home/user1 weblogic.WLST

This will create the cachedir under /home/user1, and this way all users can have their own cachedir’s without running into each other. For a more elegant solution you can create a simple unix script that wraps the call to WLST and adding the right cachedir location per user. Sample is shown below,

#!/bin/sh

# Setup classpath, probably execute setDomainEnv.sh

java -Dpython.cachedir=~ weblogic.WLST

As long as the ‘~’ resolves properly to the home directory for the user executing WLST you will never have to worry about this ‘cachedir’ related error messages.. :-)

Tags: , , , , , , ,

2 Responses to “How are python.cachedir and the error "*sys-package-mgr*: can't create package cache dir" are related”

  1. Anup says:

    This is awesome!! Information really helped.. [:)]

  2. Bipin says:

    This information really helped me!!! Good one satya