jep icon indicating copy to clipboard operation
jep copied to clipboard

Unable to run jep: Fatal Python error: No module named 'encodings'

Open Fraer opened this issue 6 years ago • 11 comments

Hello, on mac os 10.14.2, i've installed python 3.6 from https://www.python.org/ftp/python/3.6.8/python-3.6.8-macosx10.9.pkg

Jep 3.8.2 is correctly installed:

> /Library/Frameworks/Python.framework/Versions/3.6/bin/pip3 install jep
Collecting jep
Installing collected packages: jep
Successfully installed jep-3.8.2

But when i run the jep:

Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

What should i do ?

Fraer avatar Dec 25 '18 01:12 Fraer

The first thing to do is see if the jep script is able to run, this script should be located at /Library/Frameworks/Python.framework/Versions/3.6/bin/jep and running it will give a python prompt similar to running python through the command line. If the script works you can check out the environment and command it is using to see how to set an environment for jep.

The simplest way to setup the environment is to set the PYTHON_HOME environmental variable, I don't use Mac OS so I''m not sure exactly which path to use but I would guess /Library/Frameworks/Python.framework/Versions/3.6/.

bsteffensmeier avatar Dec 25 '18 16:12 bsteffensmeier

Besides the jep script, does running python from the command line work and if so can you import encodings? It sounds like the Python install may be incomplete somehow. It seems more like a Python problem than a Jep problem: https://stackoverflow.com/questions/38132755/importerror-no-module-named-encodings

ndjensen avatar Jan 03 '19 00:01 ndjensen

It happened to me on a linux VM where i had the jep package installed under /usr/local/lib64/python3.6/site-packages. Python3.6 was installed under /usr/lib64. I made use of smart library loading and it threw an error during initialization when i set the python home that follows to the jep package.

pvb05 avatar Sep 04 '19 14:09 pvb05

@PradeepBadiger I think for your use case you would need to set a separate prefix and exec_prefix in PYTHONHOME as described in the python documention. Can you start an ordinary python3.6 interpreter on your linux vm and tell us what the values of sys.prefix and sys.exec_prefix are? Unfortunatly jep does not support that format of PYTHONHOME for finding libjep so you will need to use LD_LIBRARY_PATH or -Djava.library.path to find libjep. We should add support for the multipath PYTHONHOME to LibraryLocator

bsteffensmeier avatar Sep 04 '19 17:09 bsteffensmeier

Target for 3.9.1 or 4.0.0, whichever comes first.

ndjensen avatar Sep 04 '19 17:09 ndjensen

Hi @ndjensen - This is what i see.

[root@automation02 site-packages]# python3.6 Python 3.6.8 (default, Apr 25 2019, 21:02:35) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys; >>> print(sys.prefix) /usr >>> print(sys.exec_prefix); /usr >>>

For now, I kind of work around this issue by installing the package in the actual python home location of /usr/lib64/python3.6 using below command.

python3.6 -m pip install --install-option="--prefix=/usr" jep

pvb05 avatar Sep 05 '19 16:09 pvb05

I retract my statement about targeting a fix for a release, as the idea that sys.prefix and sys.exec_prefix are different is now shown to be incorrect. At present we cannot recreate this problem and don't know how to fix it.

ndjensen avatar Sep 05 '19 18:09 ndjensen

This may be irrelevant because the original ticket is at runtime on macOS and this error I'm linking to is at build time on Linux, but when building on travisCI with the Python 3.8-dev and Python 3.9-dev branches, we received that error. https://travis-ci.org/github/ninia/jep/jobs/690178200 https://travis-ci.org/github/ninia/jep/jobs/690185988

ndjensen avatar May 22 '20 21:05 ndjensen

https://bugs.python.org/issue38236 added extra output to Python 3.8 and 3.9 when this occurs. Hopefully the extra output helps developers figure out what is going on.

ndjensen avatar May 22 '20 21:05 ndjensen

Possibly related to #284

ndjensen avatar Oct 13 '20 20:10 ndjensen

I got this on macOS with Python 3.7 and Jep 4.0 in a virtualenv. The fix was to not set PYTHONHOME which then caused the jep script to not see the virtualenv's site-packages directory.

ndjensen avatar Dec 08 '21 23:12 ndjensen