virtualenv 在 mac 中与 anaconda 不兼容

virtualenv doesn't work in mac with anaconda

我安装了 virtualenv,还安装了 2 个版本的 python。一个是通过自制软件,另一个是在蟒蛇中。但是 virtualenv 不适用于它们中的任何一个。我发现一些帖子说这是由于 python 版本混乱造成的。但即使我指向不同的 python,它仍然不起作用。有什么解决办法吗?谢谢

jzhangMBPr:~ jzhang$ virtualenv -p /Users/jzhang/anaconda/bin/python a
Already using interpreter /Users/jzhang/anaconda/bin/python
Using base prefix '/Users/jzhang/anaconda'
New python executable in /Users/jzhang/a/bin/python
ERROR: The executable /Users/jzhang/a/bin/python is not functioning
ERROR: It thinks sys.prefix is '/Users/jzhang' (should be '/Users/jzhang/a')
ERROR: virtualenv is not compatible with this system or executable

jzhangMBPr:~ jzhang$ virtualenv  a
Using base prefix '/Users/jzhang/anaconda'
New python executable in /Users/jzhang/a/bin/python
ERROR: The executable /Users/jzhang/a/bin/python is not functioning
ERROR: It thinks sys.prefix is '/Users/jzhang' (should be '/Users/jzhang/a')
ERROR: virtualenv is not compatible with this system or executable

您可能将 virtualenv 指向错误的 Python 安装。我认为这与您拥有哪个 python 解释器无关。 Virtualenv 带有一个 -p 标志,可以让您明确使用哪个解释器。

使用;

virtualenv -p python test

相反;

virtualenv test

您也可以使用 virtualenv -h,它会显示有关其他特定 virtualenv 标志的使用的帮助文档。

请检查您的conda init。对我来说 运行 :

conda init bash

解决了问题。