使用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/python3Using base prefix '/usr/local/Cellar/python3/3.4.0_1/Frameworks/Python.framework/Versions/3.4'New python executable in test/bin/python3.4Also creating executable in test/bin/pythonFailed to import the site moduleTraceback (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 MutableMappingImportError: No module named '_collections_abc'ERROR: The executable test/bin/python3.4 is not functioningERROR: 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
3 回答
潇潇雨雨
TA贡献1833条经验 获得超4个赞
简单地跑
virtualenv -p python3 envname
OP编辑后更新:
有没有在OP的版本virtualenv中的一个bug,如所描述这里。通过运行修复问题:
pip install --upgrade virtualenv
函数式编程
TA贡献1807条经验 获得超9个赞
Python 3内置了对虚拟环境的支持 - venv。使用它可能会更好。参考文档:
通过执行pyvenv脚本来创建虚拟环境:
pyvenv /path/to/new/virtual/environment
Python 3.6及更新版的更新:
作为pawciobiel正确评价,pyvenv被弃用像Python 3.6和新的方法是:
python3 -m venv /path/to/new/virtual/environment
添加回答
举报
0/150
提交
取消