為什麼每當我鍵入無意義的命令時都會生成此 python 錯誤消息?
每當我鍵入任何“廢話”命令時,都會生成此 python 錯誤消息。普通命令工作正常。知道如何調試嗎?
$ somenonexistingcommand Traceback (most recent call last): File "/usr/local/lib/python2.7/site.py", line 553, in <module> main() File "/usr/local/lib/python2.7/site.py", line 535, in main known_paths = addusersitepackages(known_paths) File "/usr/local/lib/python2.7/site.py", line 268, in addusersitepackages user_site = getusersitepackages() File "/usr/local/lib/python2.7/site.py", line 243, in getusersitepackages user_base = getuserbase() # this will also set USER_BASE File "/usr/local/lib/python2.7/site.py", line 233, in getuserbase USER_BASE = get_config_var('userbase') File "/usr/local/lib/python2.7/sysconfig.py", line 535, in get_config_var return get_config_vars().get(name) File "/usr/local/lib/python2.7/sysconfig.py", line 434, in get_config_vars _init_posix(_CONFIG_VARS) File "/usr/local/lib/python2.7/sysconfig.py", line 298, in _init_posix raise IOError(msg) IOError: invalid Python installation: unable to open /usr/include/python2.7/pyconfig.h (No such file or directory) $ echo this works fine, however this works fine, however $
編輯- 修復我的 /usr/bin/python 後,我現在得到這個不同的 python 錯誤消息:
$ yetanothernonexistingcommand Traceback (most recent call last): File "/usr/lib/command-not-found", line 10, in <module> import CommandNotFound ImportError: No module named CommandNotFound
不知何故,每當我輸入錯誤的命令時,python 就會執行。
好的,這使事情變得更清楚了。
command-not-found
是一個 python 程序,當你的命令在系統上找不到時執行。(其功能是在輸入錯誤等情況下提出替代方案和更正建議。)請參閱/usr/bin/command-not-found
。它正在嘗試導入CommandNotFound
模組並且無法導入,這清楚地指向了一個搞砸的 python 安裝。我不太熟悉command-not-found
,但我認為修復您的 Python 安裝將使問題消失。只是為了詳細說明一下,可能發生的事情是該
command-not-found
模組位於您的預設 python 不尋找它的某個地方。基本上是路徑問題。調試建議:
- 首先,輸出是什麼
$類型蟒蛇
該文件屬於什麼包/安裝?
- 與以下程式碼相對應的安裝輸出是什麼?這裡的路徑就是這個python的導入路徑。
$ python Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
$$ GCC 4.4.5 $$在 linux2 上鍵入“help”、“copyright”、“credits”或“license”以獲取更多資訊。
> > > > > > 導入 sys sys.path > > > > > > $$ ‘’, ‘/usr/lib/python2.6’, ‘/usr/lib/python2.6/plat-linux2’, ‘/usr/lib/python2.6/lib-tk’, ‘/usr/lib/python2.6/lib-old’, ‘/usr/lib/python2.6/lib-dynload’, ‘/usr/local/lib/python2.6/dist-packages’, ‘/usr/lib/python2.6/dist-packages’, ‘/usr/lib/python2.6/dist-packages/PIL’, ‘/usr/lib/python2.6/dist-packages/gst-0.10’, ‘/usr/lib/pymodules/python2.6’, ‘/usr/lib/pymodules/python2.6/gtk-2.0’, ‘/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode’ $$ > > > > >