-2

用ports卸载旧版本后找不到python脚本:

 sudo port uninstall --follow-dependents python27

但是python2.7文件在系统路径下:

➜ ~ $ which python2.7
/usr/bin/python2.7
➜ ~ $ python2.7 -V
-bash: /opt/local/bin/python2.7: No such file or directory
➜ ~ $ ll /opt/local/bin/python*
ls: /opt/local/bin/python*: No such file or directory    
➜ ~ $ ll /usr/bin/python*
-rwxr-xr-x  2 root  wheel    57K 10 12 21:47 /usr/bin/python
-rwxr-xr-x  5 root  wheel   925B 10 12 21:47 /usr/bin/python-config
lrwxr-xr-x  1 root  wheel    75B 10 12 21:47 /usr/bin/python2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
lrwxr-xr-x  1 root  wheel    82B 10 12 21:47 /usr/bin/python2.5-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config
lrwxr-xr-x  1 root  wheel    75B 10 12 21:47 /usr/bin/python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
lrwxr-xr-x  1 root  wheel    82B 10 12 21:47 /usr/bin/python2.6-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config
lrwxr-xr-x  1 root  wheel    70B 10 13 20:38 /usr/bin/python2.7 -> /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel    82B 10 12 21:47 /usr/bin/python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x  2 root  wheel    57K 10 12 21:47 /usr/bin/pythonw
lrwxr-xr-x  1 root  wheel    76B 10 12 21:47 /usr/bin/pythonw2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5
lrwxr-xr-x  1 root  wheel    76B 10 12 21:47 /usr/bin/pythonw2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6
lrwxr-xr-x  1 root  wheel    76B 10 12 21:47 /usr/bin/pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
➜ ~ $ /usr/bin/python2.7 -V
Python 2.7.5
➜ ~ $ ll /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
-rwxr-xr-x  1 root  wheel    34K 10 12 21:47 /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

PATH 值为:

➜ ~ $ echo $PATH|tr ':' '\n'
/Users/adyliu/.rvm/gems/ruby-2.0.0-p247/bin
/Users/adyliu/.rvm/gems/ruby-2.0.0-p247@global/bin
/Users/adyliu/.rvm/rubies/ruby-2.0.0-p247/bin
/Users/adyliu/.rvm/bin
/opt/local/bin
/opt/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/Users/adyliu/bin

我之前使用ports安装了python2.7.3,所以'/opt/local/bin'的路径在'/usr/bin'的路径之前,而python脚本(python2.7)在'/opt/local/ bin' 在我卸载这个 python 之前。

现在我的问题是为什么尽管文件在系统路径中却找不到 python 脚本。

➜ ~ $ for d in `echo $PATH|tr ':' ' '`;do if [ -x $d/python2.7 ]; then ls -lh $d/python2.7;fi;done
lrwxr-xr-x  1 root  wheel    70B 10 13 20:38 /usr/bin/python2.7 -> /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
➜ ~ $ which python2.7
/usr/bin/python2.7
➜ ~ $ python2.7 -V
-bash: /opt/local/bin/python2.7: No such file or directory    

如何删除命令的哈希缓存:

➜ ~ $ command -V python2.7
python2.7 is hashed (/opt/local/bin/python2.7)
➜ ~ $ type python2.7
python2.7 is hashed (/usr/bin/python2.7)
➜ ~ $ type python
python is hashed (/usr/bin/python)

更新 1

我不知道为什么现在可以立即找到“python2.7”(问题发布后 10 分钟)。

➜ ~ $ command -V python2.7
python2.7 is hashed (/usr/bin/python2.7)

更新 2

仍然找不到“python2”脚本:

➜ ~ $ python2 -V
-bash: /opt/local/bin/python2: No such file or directory
➜ ~ $ python2
-bash: /opt/local/bin/python2: No such file or directory
➜ ~ $ which python2
/usr/bin/python2
➜ ~ $ command -V python2
python2 is hashed (/opt/local/bin/python2)
➜ ~ $ python2 -V
-bash: /opt/local/bin/python2: No such file or directory
➜ ~ $ /usr/bin/python2 -V
Python 2.7.5
➜ ~ $ ll /usr/bin/python2
lrwxr-xr-x  1 root  wheel    18B 10 13 20:50 /usr/bin/python2 -> /usr/bin/python2.7
➜ ~ $ python2.7 -V
Python 2.7.5
➜ ~ $ python2 -V
-bash: /opt/local/bin/python2: No such file or directory
4

1 回答 1

0

首先检查文件的大小:

du -sh /usr/bin/python2

可能是文件不存在。

于 2013-10-13T13:37:12.280 回答