【问题标题】:How can I locate a specific version of the Python interpreter?如何找到特定版本的 Python 解释器?
【发布时间】:2015-03-24 14:07:46
【问题描述】:

我最近在我的 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.

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

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

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

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

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

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

生成的虚拟环境仍然使用 2.7.6 版本的 Python。我认为安装 Python 2.7.9 应该更新了/usr/bin/ 中的python2.7 可执行文件?

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

【问题讨论】:

  • 尝试which python 并使用该二进制文件
  • 正如@thefourtheye 所说,试试virtualenv -p $(which python) test7
  • “我认为 Python 2.7.9 的安装应该更新了/usr/bin 中的python2.7 可执行文件?” - 不,请参见例如stackoverflow.com/q/5846167/3001761 更改默认版本。

标签: python python-2.7 virtualenv virtualenvwrapper


【解决方案1】:

使用which 从命令行查找正在运行的可执行文件,然后使用它来创建虚拟环境。

类似

virtualenv -p $(which python) test7

【讨论】:

  • 完美运行。就我而言,它是virtualenv -p /Library/Frameworks/Python.framework/Versions/2.7/bin/python test7
【解决方案2】:

/usr/bin/python2.7 只是一个指向实际 python 二进制文件的符号链接,它可能位于其他地方。如果您执行 /usr/bin/python2.7 --version 很可能会显示“Python 2.7.6”。

这个我在mac上没试过,但是在linux上做过,就是在我的路径/users//mypython中获取特定版本的python并手动编译,然后修改/usr/bin中的符号链接/python 指向我的版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-13
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-18
    • 2014-06-17
    • 1970-01-01
    • 2018-06-27
    相关资源
    最近更新 更多