如何找到 Python 解释器的特定版本?

How can I locate a specific version of the Python interpreter?

我最近在 Mac 上从 Python 2.7.6 更新到 Python 2.7.9。我的问题是我无法使用带有 -p 标志的 Python 2.7.9 创建新的 virtualenv

当我在虚拟环境外打开 Python shell 时,它 使用 2.7.9:

localhost:test6 brendan$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

但是,当我使用 virtualenv or mkvirtualenv 创建新的虚拟环境时,它继续使用 2.7.6。

我知道我可以使用 -p 标志来使用特定版本的 Python(例如 3.0、2.6 等)创建虚拟环境,但每个版本都有自己的可执行文件,例如

virtualenv -p /usr/bin/python3.0 test6

virtualenv -p /usr/bin/python2.6 test7

我似乎没有 python2.7.9 可执行文件位于 /usr/bin 或其他任何地方。我确实有一个 python2.7 可执行文件,但是如果我指定这个:

virtualenv -p /usr/bin/python2.7 test7

生成的虚拟环境仍然使用Python的2.7.6版本。我认为 Python 2.7.9 的安装应该已经更新了 /usr/bin/?

中的 python2.7 可执行文件

所以我的问题是:我的 Python 2.7.9 可执行文件位于何处,以及在创建新虚拟环境时如何指定它?

使用which从命令行中找到运行哪个可执行文件,然后使用它来创建virtualenv。

类似

virtualenv -p $(which python) test7

/usr/bin/python2.7 只是符号 link 到实际的 python 二进制文件,它可能位于其他地方。如果您执行 /usr/bin/python2.7 --version,它很可能会显示 "Python 2.7.6"。

我没有在mac上试过这个,但是在Linux上试过,是为了获取python的特定版本并在我的路径/users/中手动编译它/mypython,然后修改/usr/bin/python中的符号link指向我的版本