无法为 virtualenv 加载 Python 3.5 解释器

cannot load Python 3.5 interpreter for virtualenv

我已经通过 Anaconda 在 OSX 系统上安装了 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

代码returns一个[Errno 13]权限被拒绝

> 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
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版本不能描述为"reasonably functional",因为。这使得 venv 模块不可能 bootstrap pip 进入你的 virtualenv。所以你需要在没有 pip 的情况下构建你的 venv,然后手动安装它:

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

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