-2

ポートを使用して古いバージョンをアンインストールした後、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

以前にポートを使用して python2.7.3 をインストールしたため、「/opt/local/bin」のパスは「/usr/bin」のパスの前にあり、python スクリプト (python2.7) は「/opt/local/」にありました。この python をアンインストールする前に bin'.

私の質問は、ファイルがシステム パスにあるにもかかわらず、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