在virtualenv中使用Python 3

问题:

使用virtualenv,我使用默认版本的Python(2.7)运行我的项目。在一个项目中,我需要使用Python 3.4。
我使用brew install python3将其安装在我的Mac上。现在,如何创建一个使用新版本的virtualenv?
例如sudo virtualenv envPython3
如果我尝试:

virtualenv -p python3 test

我得到:

Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python3/3.4.0_1/Frameworks/Python.framework/Versions/3.4'
New python executable in test/bin/python3.4
Also creating executable in test/bin/python
Failed to import the site module
Traceback (most recent call last):
  File "/Users/user/Documents/workspace/test/test/bin/../lib/python3.4/site.py", line 67, in <module>
    import os
  File "/Users/user/Documents/workspace/test/test/bin/../lib/python3.4/os.py", line 634, in <module>
    from _collections_abc import MutableMapping
ImportError: No module named '_collections_abc'
ERROR: The executable test/bin/python3.4 is not functioning
ERROR: It thinks sys.prefix is '/Users/user/Documents/workspace/test' (should be '/Users/user/Documents/workspace/test/test')
ERROR: virtualenv is not compatible with this system or executable

回答:

简单运行

virtualenv -p python3 envname

OP编辑后更新:
在OP的版本的virtualenv中有一个错误,如here所述。运行以下问题已解决:

pip install --upgrade virtualenv

 
 
Code问答: http://codewenda.com/topics/python/
Stackoverflow: Using Python 3 in virtualenv

*转载请注明本文链接以及stackoverflow的英文链接

发表评论

电子邮件地址不会被公开。 必填项已用*标注

3 + 7 =