在指示MacPorts切换到Python 3.4后,python --version
仍然输出2.7.10。请注意,“哪个python”确实显示/ opt / local / bin在我的PATH中/ usr / bin /之前出现:
$ which python
/opt/local/bin/python
$ python --version
Python 2.7.10
$ ls -l /opt/local/bin/python
lrwxr-xr-x 1 root wheel 24 Aug 1 10:00 /opt/local/bin/python -> /opt/local/bin/python2.7
$ sudo port select --list python
Available versions for python:
none
python26-apple
python27 (active)
python27-apple
python34
$ sudo port select --set python python34
Selecting 'python34' for 'python' succeeded. 'python34' is now active.
$ which python
/opt/local/bin/python
$ python --version
Python 2.7.10
$ ls -l /opt/local/bin/python
lrwxr-xr-x 1 root wheel 24 Aug 1 10:00 /opt/local/bin/python -> /opt/local/bin/python3.4
请注意符号链接的确如何更改,但声明的版本不会更改。是什么给了什么?
答案 0 :(得分:3)
tl; dr:运行hash -r
。
出于速度原因,当您在shell中键入python
时,shell会保留一个可执行文件的缓存。
考虑没有这样的缓存,shell必须做什么:对于你输入的每个命令(不是绝对路径),shell必须
$PATH
中的条目以及每个条目stat(2)
系统调用,以测试该命令是否存在于当前搜索的目录中。请记住,这可能涉及缓慢的旋转磁盘,甚至是最初开发shell时的网络文件系统。为了加快速度,大多数shell只对每个命令执行一次,直到更改$PATH
,或者手动告诉shell删除缓存(例如在bash中使用hash -r
{ {1}}在其他一些shell中。)
但对我来说,有些shell还会缓存符号链接。