How to check the classpath where Jython ScriptEngine looks for python module?

混江龙づ霸主 提交于 2019-12-02 07:06:20

sys.path is a list of strings that specifies where Jython (and Python) searches for modules. You can check its value like so:

engine.eval("import sys; print sys.path");

To add a directory to sys.path, use the JYTHONPATH environment variable. If yourmodule is installed in /path/to/modules/yourmodule, it would look like this:

export JYTHONPATH=/path/to/modules

Another way is to use the python.path property.


Unfortunately, in the case of psycopg2 the above won't help since that package is a C extension and therefore only compatible with CPython. Perhaps you can use the port of Psycopg for Ctypes instead.

waypoint100

An alternative way to add path to folder with custom python libs using ScriptEngine:

engine.eval("import sys; sys.path.append(\"/some/path/to/folder/withpylibs\")");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!