python 安装无效:无法打开/usr/lib/python2. 7/config/Makefile ( 没有此类文件或者目录)"

分享于 

3分钟阅读

ubuntu

  繁體

问题

我不记得用python安装做了什么,但现在,当我尝试打开python命令行时出现错误:


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$ 




答案1

你可以从这里下载它们:python2.7python2.7-minimal,要下载正确的版本,

然后打开终端,转到下载文件的目录,并安装它们:


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


sudo dpkg -i python2.7*.deb



注:命令中的dpkg名称不正确,用你下载的文件名替换它们。


答案2

缺少的pyconfig.h来自以下包


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



我通过安装python-dev解决了这个问题


sudo apt-get install python-dev




答案3

丢失的文件是软件包python2.7-minimal的一部分,尝试重新安装:


sudo apt-get --reinstall install python2.7-minimal