【问题标题】:How to quickly switch between the different Python executables on my Mac?如何在我的 Mac 上的不同 Python 可执行文件之间快速切换?
【发布时间】:2015-04-22 03:56:25
【问题描述】:

谁能告诉我如何在我的 Mac 上快速切换以下 Python 可执行文件?

我希望能够在一个特定的虚拟环境中规定使用 psiTurk 所需的 Enthought Canopy 可执行文件

  • “本机到计算机”/usr/local/bin/python
  • “本地到虚拟环境”/Users/brendan/Dropbox/workspace/psiturktestfive
  • “Enthought Canopy”/Users/brendan/Library/Enthought/Canopy_64bit/User/bin/python
  • ".bash_profile" /Library/Frameworks/Python.framework/Versions/2.7/bin/python

是否有一个简单的终端命令可以做到这一点?

目前,如果我编辑我的 .bash_profile,我只能让我的机器使用 Enthought Canpy 版本,但是一旦我为项目激活新的虚拟环境,就会切换到虚拟环境本地 python 可执行文件

任何帮助都一如既往,非常感谢。

编辑:

以下错误是我尝试使用virtualenv -p /Users/brendan/Library/Enthought/Canopy_64bit/User/bin/python canopy时收到的错误

localhost:workspace brendan$ virtualenv -p /Users/brendan/Library/Enthought/Canopy_64bit/User/bin/python canopy
Running virtualenv with interpreter /Users/brendan/Library/Enthought/Canopy_64bit/User/bin/python
Using base prefix '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents'
New python executable in canopy/bin/python
dyld: Library not loaded: @rpath/Python
  Referenced from: /Users/brendan/Dropbox/workspace/canopy/bin/python
  Reason: image not found
ERROR: The executable canopy/bin/python is not functioning
ERROR: It thinks sys.prefix is u'/Users/brendan/Dropbox/workspace' (should be u'/Users/brendan/Dropbox/workspace/canopy')
ERROR: virtualenv is not compatible with this system or executable
localhost:workspace brendan$ 

【问题讨论】:

    标签: python python-2.7 virtualenv


    【解决方案1】:

    您可以使用以下方法创建virtualenv

    virtualenv -p /Users/brendan/Library/Enthought/Canopy_64bit/User/bin/python canopy
    

    然后做

    source canopy/bin/activate
    

    (如果您在 Unix 上并使用 Bash)。

    Virtualenv 可以使用pip install virtualenv 安装,或按照home page 上的说明进行安装

    【讨论】:

    • 我不知道我可以使用不同版本的 Python 创建虚拟环境。不幸的是,当我尝试您的解决方案时,出现上述错误(请参阅编辑)。
    • 你能启动 /Users/brendan/Library/Enthought/Canopy_64bit/User/bin/python(点击或命令行)吗?
    • 是的,我可以双向启动
    • [您无法使用 virtualenv 创建 Enthought Canopy 虚拟环境。][1] [1]: support.enthought.com/entries/…
    猜你喜欢
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2010-12-12
    • 2021-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多