"invalid Python installation: unable to open /usr/lib/python2.7/config/Makefile (No such file or directory)"

I have done something with my python installation, don't remember what exactly. But I am getting an error when I try to open python command line now:

richard@richard-desktop:~/projects/hello$ python
Traceback (most recent call last):
  File "/usr/lib/python2.7/site.py", line 562, in <module>
    main()
  File "/usr/lib/python2.7/site.py", line 544, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/lib/python2.7/site.py", line 271, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/lib/python2.7/site.py", line 246, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/lib/python2.7/site.py", line 236, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/lib/python2.7/sysconfig.py", line 577, in get_config_var
    return get_config_vars().get(name)
  File "/usr/lib/python2.7/sysconfig.py", line 476, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/usr/lib/python2.7/sysconfig.py", line 344, in _init_posix
    raise IOError(msg)
IOError: invalid Python installation: unable to open /usr/lib/python2.7/config/Makefile (No such file or directory)
richard@richard-desktop:~/projects/hello$ 

Is there some way to fix this?


If you can't use apt-get try downloading python .debs and install them manually.

You can download them from here: python2.7 and python2.7-minimal. Don't forget to download the correct version for your architecture.

After that just open a terminal, change to the directory where you have downloaded the files and install them:

sudo dpkg -i python2.7-miminal*.deb
sudo dpkg -i python2.7*.deb

Note: the names in the dpkg command are not completely right. So replace them with the correct name of the files you downloaded.


Here is some updated information when i was resolving this problem. the missing pyconfig.h comes from the following package

libpython2.7-dev:amd64: /usr/include/python2.7/pyconfig.h

i am not sure if reinstalling python-minimal helps. i solved the problem by installing python-dev

sudo apt-get install python-dev

which installed the missing libpython files. I hope this helps someone in the future.