Ubuntu – Bash tries to run python on unknown command and fails in Py_Initialize


Running Ubuntu 14.04 and updater says that all software is up to date. Have tried rebooting.

I am preparing for a class that uses Python. I have installed it and it works fine. However, I now have this problem:
When I type an unknown command into bash, I get a python error:

cliff@Climate:~$ UnknownProgram

Fatal Python error: Py_Initialize: Unable to get the locale encoding
  File "/usr/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,\
SyntaxError: invalid syntax 

cliff@Climate:~$ env | grep -i python 

cliff@Climate:~$ which UnknownProgram    
cliff@Climate:~$ which python   

cliff@Climate:~$ python --version  
Python 2.7.6

cliff@Climate:~$ echo $PATH

I think that pycharm also installed some python3 on the box.

I have found that /usr/lib/command-not-found includes a shebang for python3. I guess that it is somehow picking up the wrong Py_Initialize file. How do I correct this since I need python 2.7 for the class?

Best Answer

Removing the export PYTHONPATH from my .bashrc has fixed the problem. I now get the normal processing if I type in an incorrect command name. I will have to do some more research to be sure that my python 2.7 code is picking up the correct modules without that extra environment setting.

Related Question