ninia / jep

Embed Python in Java
Other
1.33k stars 150 forks source link

The specified Python environment cannot be found in Linux #340

Closed Marmot01 closed 3 years ago

Marmot01 commented 3 years ago

Describe the problem I use MainInterpreter setInitParams (pyConfig) to set my python environment, but the program will automatically find the python environment under system, this is not what I want.

Environment :

MyCode : public class Demo01 { public static void main(String[] args) throws JepException { PyConfig pyConfig = new PyConfig(); String pyHome = "/home/liuzao/Desktop/python33/python3.6/"; pyConfig.setPythonHome(pyHome); LibraryLocator.findJepLibrary(pyConfig); MainInterpreter.setInitParams(pyConfig); NamingConventionClassEnquirer enquirer = new NamingConventionClassEnquirer(true); enquirer.addTopLevelPackageName("command"); JepConfig jepConfig = new JepConfig(); jepConfig.setClassEnquirer(enquirer); jepConfig.setRedirectOutputStreams(true); SharedInterpreter.setConfig(jepConfig); SharedInterpreter interpreter = new SharedInterpreter(); interpreter.exec("import sys"); interpreter.exec("print(sys.path)"); interpreter.exec("import numpy"); interpreter.exec("print(20)"); interpreter.close();
} }

Error Fatal Python error: Py_Initialize: Unable to get the locale encoding ModuleNotFoundError: No module named 'encodings' Current thread 0x00007fdfb6b7d700 (most recent call first): The reason for the error is that the system could not find the Python environment, but I have use MainInterpreter.setInitParams(pyConfig); to set the environment. I want to know how do I set so that the program use Python environment I want.

bsteffensmeier commented 3 years ago

Jep prefers to use whatever python library is configured to load for your system. To change the way your system loads libraries you should set the LD_LIBRARY_PATH environmental variable to include the directory that contains the version libpython you want to use.

ndjensen commented 3 years ago

Closing as resolved.