• Register
0 votes

Problem :

On installing Anaconda on Ubantu getting below Python error on miss-typed commands
fatal python error: py_initialize: unable to get the locale encoding
6 5 3
6,930 points

Please log in or register to answer this question.

2 Answers

0 votes


I have also faced similar issues in the past , so I traced it back to how bash handles "command not found". In Ubuntu 14.04 

/etc/bash.bashrc has the following function:

if [ -x /usr/lib/command-not-found ]; then
    function command_not_found_handle {
        # check because c-n-f could've been removed in the meantime
        if [ -x /usr/lib/command-not-found ]; then
            /usr/bin/python /usr/lib/command-not-found -- $1
            return $?
           return 127

Further Readings:


9 7 4
38,600 points
0 votes

It is suggested to use PYTHONPATH. Mostly it is not needed and causes many things to break like this by making one Python load things form another Python.


 When you try to execute the command in python 3.5. Then the error message can occur;

Fatal Python error: Py_Initialize: Unable to get the locale encoding

InmportError: No module named ‘encodings’

Current thread 0x00007ff41bf46700 (most recent call first):

Aborted (core dumped)

What could be the problem?

How to fix- Fatal Python error: Py_Initialize: Unable to get the locale encodings

ImportError: No module named ‘encodings’


This error can be due to multiple installations on your machine and the command python3.5 might be referring to libraries that belong to different versions of Python. There can be another reason “The command python3.5 is not able to find the PYTHON installation path.

Use the below lines to solve the error:

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

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


Make sure that you have set the correct installation path of Python3.5.

Python 3.5.9 (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.



11 5 2
3,890 points

Related questions

0 votes
1 answer 408 views
Problem : When I executed: pip install xgboost I got this: Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/w4/w49s3mn91plbhyjwf8qjkpxc0000gn/T/pip-build-61dms1/xgboost/
asked Oct 21, 2019 peterlaw 6.9k points
0 votes
1 answer 528 views
Problem: I have recently started learning Python so I have only fundamental knowledge in Python. Please find below my Transaction class for your reference: class Transaction(object):     def __init__(self, company, num, price, date, is_buy):         self.company = company         ... Python and because of lockdown I am unable to find any help to fix this issue. So I am posting my question here.
asked Aug 10, 2020 Raphael Pacheco 4.9k points
1 vote
1 answer 160 views
Problem: I am getting an interesting error: valueerror: mixing iteration and read methods would lose data while I’m trying to run my script on python. I have no idea about this problem. I am trying to open a text file in my program and read it. Please ... test_file I think I am doing something wrong with using the readline() function. I am looking forward to having a solution. Thanks, guys.
asked Mar 29, 2020 Gavin 15.3k points
0 votes
1 answer 103 views
Problem : I am unable to understand what am I missing here: Sort my_short_names in reverse alphabetic order. The sample output from the given program as below : ['Tody', 'Samy', 'Joey', 'Jany', 'Anny'] Below is my code for your reference : my_short_names = ['Jany', 'Samy', 'Anny', 'Joey', 'Tody'] my_short_names.sort() print(my_short_names)
asked Jan 8, 2020 alecxe 7.5k points
0 votes
1 answer 381 views
Problem : I am trying to execute below commands. import numpy as np import cv But I am getting following error on my console: >>> runfile('/Users/isaiahnields/.spyder2/temp.py', wdir='/Users/isaiahnields/.spyder2') RuntimeError: module compiled against API version a but this ... it is not working. I had added cv.py to the python2.7 folder in Spyder-Py2 is there anything else I need to add?
asked Dec 4, 2019 alecxe 7.5k points
0 votes
1 answer 1.3K views
Problem : I am using the sqlite3 to store the values into database, My problem is that I have created lineedits through which I am trying to extract values and store it to the variables and pass this variables to the insert query but i am facing below error at line values(?, ... ?,?,?)''',(self.uname,self.passwd,self.permssn)) print ('inserted row') self.createDb.commit() Any solution on my error?
asked Jan 18, 2020 jwilliam 3.9k points
1 vote
1 answer 25 views
Problem : Recently I have started learning Homebrew. Now if I try to run Homebrews brew doctor command on my Mac OS X 10.9.2 I have started receiving the below listed warning message: Warning: Python is installed at /Library/Frameworks/Python.framework Homebrew only ... /usr/local/bin/python. But still if I rerun the brew doctor command I am still facing the same warning message listed above.
asked Apr 4, 2020 morrisBson 3.2k points
0 votes
1 answer 87 views
Problem : I have recently installed the opencv 2.4.8 . I am also using python 2.7. I have tried to add my opencv lib to the python according to the tutorial however when I wanted to import my opencv I encountered below error: import cv2 RuntimeError: module compiled ... above error. How can I fix above problem? I researched on still I am unable to find the solutions. Currently I use Windows 7.
asked Dec 21, 2019 alecxe 7.5k points
0 votes
1 answer 889 views
Problem : I am trying to deploy my Python Flask application in my Azure web app. I had created web app(Flask) and published the code. After publishing it, I am facing below error from the site. The page cannot be displayed because an internal server error ... . But this was the case only in my subscription(my free subscription with MSDN). But it was working fine in the Organisation subscription.
asked Dec 16, 2019 alecxe 7.5k points
0 votes
1 answer 1.3K views
Problem : I am trying to convert my working Python 2.7 code into Python 3 code but I am facing following error post data should be bytes, an iterable of bytes, or a file object. it cannot be of type str.
asked Nov 16, 2019 peterlaw 6.9k points