2013-04-29 76 views
3

我意外地替換了位於/ usr/local/bin /的python二進制文件。從那以後,我無法運行任何python腳本,甚至不能運行python的交互模式。我的python不起作用

$ 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 558, in get_config_var 
    return get_config_vars().get(name) 
    File "/usr/lib/python2.7/sysconfig.py", line 457, in get_config_vars 
    _init_posix(_CONFIG_VARS) 
    File "/usr/lib/python2.7/sysconfig.py", line 303, in _init_posix 
    makefile = _get_makefile_filename() 
    File "/usr/lib/python2.7/sysconfig.py", line 297, in _get_makefile_filename 
    return os.path.join(get_path('platstdlib').replace("/usr/local","/usr",1), "config" + (sys.pydebug and "_d" or ""), "Makefile") 
AttributeError: 'module' object has no attribute 'pydebug' 

我看到了相關的問題「AttributeError的:‘模塊’對象有沒有屬性‘pydebug’」的錯誤,但我仍然無法弄清楚如何來解決這個問題。

當我嘗試重新安裝將出現相同的錯誤:

$ sudo apt-get install python2.7-minimal 
[sudo] password for : 
Reading package lists... Done 
Building dependency tree  
Reading state information... Done 
python2.7-minimal is already the newest version. 
The following packages were automatically installed and are no longer required: 
    libgsasl7 libmailutils2 libntlm0 
Use 'apt-get autoremove' to remove them. 
0 upgraded, 0 newly installed, 0 to remove and 402 not upgraded. 
4 not fully installed or removed. 
After this operation, 0 B of additional disk space will be used. 
Do you want to continue [Y/n]? Y 
Setting up python2.7-minimal (2.7.1-5ubuntu2.2) ... 
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 558, in get_config_var 
    return get_config_vars().get(name) 
    File "/usr/lib/python2.7/sysconfig.py", line 457, in get_config_vars 
    _init_posix(_CONFIG_VARS) 
    File "/usr/lib/python2.7/sysconfig.py", line 303, in _init_posix 
    makefile = _get_makefile_filename() 
    File "/usr/lib/python2.7/sysconfig.py", line 297, in _get_makefile_filename 
    return os.path.join(get_path('platstdlib').replace("/usr/local","/usr",1), "config" + (sys.pydebug and "_d" or ""), "Makefile") 
AttributeError: 'module' object has no attribute 'pydebug' 
dpkg: error processing python2.7-minimal (--configure): 
subprocess installed post-installation script returned error exit status 1 
dpkg: dependency problems prevent configuration of python2.7: 
python2.7 depends on python2.7-minimal (= 2.7.1-5ubuntu2.2); however: 
    Package python2.7-minimal is not configured yet. 
dpkg: error processing python2.7 (--configure): 
dependency problems - leaving unconfigured 
dpkg: dependency problems prevent configuration of libpython2.7: 
libpython2.7 depends on python2.7 (= 2.7.1-5ubuntu2.2); however: 
    Package python2.7 is not configured yet. 
dpkg: error processing libpython2.7 (--configure): 
dependency problems - leaving unconfigured 
dpkg: dependency problems prevent configuration of python2.7-dev: 
python2.7-dev depends on python2.7 (= 2.7.1-5ubuntu2.2); however: 
    Package python2.7 is not configured yet. 
python2.7-dev depeNo apport report written because the error message indicates its a followup error from a previous failure. 
                                  No apport report written because the error message indicates its a followup error from a previous failure. 
                      No apport report written because MaxReports is reached already 
                                     nds on libpython2.7 (= 2.7.1-5ubuntu2.2); however: 
    Package libpython2.7 is not configured yet. 
dpkg: error processing python2.7-dev (--configure): 
dependency problems - leaving unconfigured 
Errors were encountered while processing: 
python2.7-minimal 
python2.7 
libpython2.7 
python2.7-dev 
E: Sub-process /usr/bin/dpkg returned an error code (1) 
+0

爲什麼不重新安裝Python? – Isaac 2013-04-29 16:24:21

+1

我已經試過並且不起作用 – Geparada 2013-04-29 16:25:07

+0

你的操作系統是什麼? – 2013-04-29 16:26:16

回答

4

的問題是,你打/usr/local/bin/python代替/usr/bin/python

您可以將其移出的方式運行類似...

mv /usr/local/bin/python /usr/local/bin/python.old 

...爲根,或者如果你確定你不需要它,那麼就刪除它與...

rm /usr/local/bin/python 

如果仍然慶典嘗試運行/usr/local/bin/python和運行type python打印...

python is hashed (/usr/local/bin/python) 

...然後執行hash -r來清除哈希表。

這並不是/usr/bin/python複製到/usr/local/bin/python一個好主意,否則你可能會得到問題的下一次你apt-get upgrade更新蟒蛇,即它會更新/usr/bin/python,但/usr/local/bin/python仍然會被默認運行。

+0

是的,這是問題......但是當我mv/usr/local/bin/python /usr/local/bin/python.old bash:/ usr/local/bin/python:沒有這樣的文件或目錄...我怎麼能告訴bash使用/ usr/bin/python insted/usr/local/bin/python? – Geparada 2013-04-29 16:47:17

+0

cp/usr/bin/python/usr/local/bin /是簡單的解決方案。謝謝!!! – Geparada 2013-04-29 16:49:35

+1

@Geparada如果你確定'/ usr/local/bin/python'沒有文件,那麼使用'hash -r'來清除bash哈希表,並且它應該選擇'/ usr/bin/python' 。 – Aya 2013-04-29 16:49:41

0

您必須重新安裝。 這是一個更好的解決方案。 這是我在Ubuntu上使用終端的最佳安裝。 嘗試: Install Python and cherrypy

而且你看看答案在這個問題上

Installation python

+0

當我嘗試這樣做時,我有同樣的錯誤: 「AttributeError:'模塊'對象沒有屬性'pydebug'」 – Geparada 2013-04-29 16:31:00

+0

嘗試安裝如何在答案上的寵物 – 2013-04-29 16:41:12

2

貌似這個事做與調試特製一個Python版本。

我建議你重新安裝Python和apt-get的:

sudo apt-get install --reinstall python2.7 

你的問題似乎同樣喜歡this SO question about sys.pydebug