使用 Conda 和 Tox 进行错误 运行 测试

Error running tests with Conda and Tox

我在使用 Conda 创建虚拟环境时使用 Tox 进行测试时遇到问题 运行。重现错误的步骤如下。

下载存储库(它很小)并cd到它:

git clone https://github.com/opensistemas-hub/osbrain.git
cd osbrain

使用 Conda 创建虚拟环境:

conda create -n asdf python=3.5
source activate asdf
pip install tox

尝试 运行 测试(注意 Python 3.5 是 tox.ini 文件中唯一的 Python 解释器集:

tox

我希望 Tox 能够使用 Conda 虚拟环境中可用的 Python 3.5 解释器来 运行 测试。但是,相反,我收到一个错误:

ERROR: The executable ~/osbrain/.tox/py35/bin/python3.5 is not 
functioning
ERROR: It thinks sys.prefix is '/usr' (should be '~/osbrain/.tox/py35')
ERROR: virtualenv is not compatible with this system or executable
Running virtualenv with interpreter ~/.miniconda3/envs/asdf/bin/python3.5

我的问题是:为什么会出现该错误,我该如何避免? (即:我如何 运行 在本地为该项目进行测试并使用 Tox?)

Virtualenv 和 conda/conda-env 目前不能一起玩。参见 https://github.com/conda-forge/staged-recipes/issues/1139 and https://groups.google.com/a/continuum.io/forum/#!topic/conda/63B0jnPR-V4

更新

还相关:https://bitbucket.org/hpk42/tox/issues/273/support-conda-envs-when-using-miniconda

我通过 conda installing virtualenv 设法解决了这个问题:

conda install virtualenv

不建议自己使用 virtualenv(坚持使用 conda 环境)。但是,当 tox 在内部查找包时,它至少会找到兼容的版本。