无法为virtualenv加载Python 3.5解释器

时间:2016-09-22 04:18:34

标签: python python-2.7 python-3.x virtualenv

我已经在OSX系统上通过Anaconda安装了Python 3.5。安装并激活虚拟环境后,

virtualenv venv
source venv/bin/activate

Python版本是Python 2.7.10。虽然我们可以在virtualenv中加载我们选择的解释器,但“/ usr / bin /”只包含Python 2.6和2.7的文件夹。找到Anaconda python 3.5路径后(/Users/Username/anaconda/lib/python3.5) 并尝试加载它,

  

for:virtualenv -p /Users/Username/anaconda/lib/python3.5 venv

代码返回[Errno 13] Permission Denied

> Running virtualenv with interpreter /Users/Username/anaconda/lib/python3.5
> Traceback (most recent call last):   File "/usr/local/bin/virtualenv",
> line 11, in <module>
>     sys.exit(main())   File "/Library/Python/2.7/site-packages/virtualenv.py", line 790, in main
>     popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)   File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",
> line 710, in __init__
>     errread, errwrite)   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",
> line 1335, in _execute_child
>     raise child_exception
OSError: [Errno 13] Permission denied
  

for:virtualenv -p /Users/Username/anaconda/bin/python3.5 venv

似乎还有其他类型的错误...

Running virtualenv with interpreter /Users/Username/anaconda/bin/python3.5
Using base prefix '/Users/Username/anaconda'
New python executable in venv/bin/python3.5
Not overwriting existing python script venv/bin/python (you must use venv/bin/python3.5)
ERROR: The executable venv/bin/python3.5 is not functioning
ERROR: It thinks sys.prefix is '/Users/Username/.../targetfolder' (should be '/Users/Username/.../targetfolder/venv')
ERROR: virtualenv is not compatible with this system or executable

1 个答案:

答案 0 :(得分:2)

ERROR: The executable venv/bin/python3.5 is not functioning
ERROR: It thinks sys.prefix is '/Users/Username/.../targetfolder' (should be '/Users/Username/.../targetfolder/venv')
ERROR: virtualenv is not compatible with this system or executable

尝试组合不兼容的Python版本和virtualenv工具会导致此错误。我不确定不兼容性来自哪里,但我确实知道如何解决它。

假设您的Python功能合理且近期(阅读:3.3或更高版本),这应该始终有效:

/path/to/python3.5 -m venv venv

第一个venv是venv module。第二个是要创建virtualenv的目录的名称。这个命令要求Python自己创建一个virtualenv,而不是炮轰出第三方工具。因此,我们可以合理地相信Python会正确地做到这一点,特别是它不会与自身不兼容。

不幸的是,与Anaconda一起安装的Python版本不能被描述为“合理运行”,因为it lacks ensurepip。这使得venv模块无法将pip引导到你的virtualenv中。所以你需要在没有pip的情况下构建你的venv,然后手动安装它:

/path/to/python3.5 -m venv --without-pip venv

然后从virtualenv中下载并运行get-pip.py