如何在我的Mac上的不同Python可执行文件之间快速切换?

时间:2015-02-20 12:55:30

标签: python python-2.7 virtualenv

有谁能告诉我如何在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

是否有一个简单的终端命令来执行此操作?

目前我只能使我的机器使用Enthought Canpy版本,如果我编辑我的.bash_profile但是一旦我为一个项目激活一个新的虚拟环境就切换到虚拟环境本地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$ 

1 个答案:

答案 0 :(得分:2)

您可以使用以下方式创建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

上的说明操作