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

让人想犯罪 __ 提交于 2019-11-30 15:14:59
Ken Li

I have the same error when I install Anaconda with Python 3.6. The error is resolved by adding an environment variable "PYTHONPATH" which point to the installation location of Python.

I refer to the following link,

Py_Initialize fails - unable to load the file system codec

Setup: MAC OSX ANACONDA

It happens when there are multiple versions of python installed or partially deleted environments are present i.e just removing the packages/installations, not the path variables.

Things to check upfront:

1. echo $PYTHONHOME
2. echo $$PYTHONPATH

If not, set the environment variables by updating your .bashrc or .bash_profile using

1. export PYTHONHOME="/Users/<user>/anaconda3/""
2. export PYTHONPATH=$PYTHONHOME/bin

and try again. If this doesn't solve your problem then, search for folders with the name "encodings" listed in your machine.

find / -type d -name "encodings" which prints a list of directories having a folder named "encodings".

Remove all directories not pointing to your python in use.

rm -rf <directory>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!