1. Home
  2. Linux
  3. How to Fix Python Fatal error: Py_Initialize: Unable to get the locale encoding [Solved]

How to Fix Python Fatal error: Py_Initialize: Unable to get the locale encoding [Solved]

I had successfully compiled Python3.5 from source. But when I execute ‘python3.5‘ command, I get an error message as “Fatal Python error: Py_Initialize: Unable to get the locale encoding. ImportError: No module named encodings“.

Here’s the complete error message:

# python3.5
 Fatal Python error: Py_Initialize: Unable to get the locale encoding
 ImportError: No module named 'encodings'
 Current thread 0x00007ff41bf46700 (most recent call first):
 Aborted (core dumped)

What could be the problem?

python module error

Solution:

The problem might be due to multiple Python installations on your machine and the command ‘python3.5‘ might be referring to libraries that belong to a different version of Python. Well, there could be another reason – the command ‘python3.5‘ is not able to find PYTHON installation path. The below lines will be a good try for this error:

# export PYTHONHOME=/usr/local/lib/python3.5/
# export PYTHONPATH=/usr/local/lib/python3.5/

Note: Make sure to set the correct installation path of Python3.5.

Now, try invoking python3.5 and it should work.

# python3.5
Python 3.5.0 (default, Nov 6 2015, 16:57:04)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Updated on September 1, 2017

Was this article helpful?

Related Articles

Comments

Leave a Comment