在Ubuntu系统上,我试图用tox和多个python版本测试一个python包。我试图测试的一个python版本是64位Anaconda Python 2.7。在我开始使用Tox进行测试之前,我首先需要让virtualenv与Anaconda合作,因为Tox在内部使用virtualenv。
如您所见,virtualenv已安装在我的Anaconda环境中:
$ conda install virtualenv
Fetching package metadata: ....
Solving package specifications: ....................
# All requested packages already installed.
# packages in environment at /home/me/software/anaconda:
#
virtualenv 13.0.1 py27_0
但是,尝试创建虚拟环境失败:
$ mkvirtualenv test
New python executable in test/bin/python
Installing setuptools, pip...
Complete output from command /home/me/....envs/test/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/me/.local/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/__init__.py", line 9, in <module>
File "/home/me/.local/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/log.py", line 8, in <module>
File "/home/me/.local/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/backwardcompat/__init__.py", line 66, in <module>
File "/home/me/software/anaconda/lib/python2.7/urllib2.py", line 93, in <module>
import hashlib
File "/home/me/software/anaconda/lib/python2.7/hashlib.py", line 138, in <module>
_hashlib.openssl_md_meth_names)
AttributeError: 'module' object has no attribute 'openssl_md_meth_names'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "/home/me/software/anaconda/bin/virtualenv", line 6, in <module>
sys.exit(main())
File "/home/me/.local/lib/python2.7/site-packages/virtualenv.py", line 824, in main
symlink=options.symlink)
File "/home/me/.local/lib/python2.7/site-packages/virtualenv.py", line 992, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/home/me/.local/lib/python2.7/site-packages/virtualenv.py", line 960, in install_wheel
'PIP_NO_INDEX': '1'
File "/home/me/.local/lib/python2.7/site-packages/virtualenv.py", line 902, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/me/....envs/test/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1
如何让virtualenv与Anaconda合作?
答案 0 :(得分:1)
我觉得回答这个问题已经很晚了,你可能已经解决了......但仍然没有答案,所以无论如何我都会给你一个! 我将提供可以在其他网站上找到的食谱,我将列出各种来源,以便如果链接中断,答案仍然可以在这里看到。
首先,mkvirtualenv
是一个由virtualenvwrapper包定义的命令,而不仅仅是virtualenv。
其次,使用Anaconda python创建虚拟环境的方式(命令)与安装了virtualenv的标准python不同。
使用Anaconda python,要创建virtualenv,应按照以下顺序创建一个:
conda create -n envname python=x.x anaconda
其中envname
是您的虚拟环境的名称,并且您已通过以下方式检索了要使用的python版本:
conda search "^python$"
要激活虚拟环境,请执行以下操作:
source activate envname
将软件包安装到新的虚拟环境类型
conda install -n envname [package]
停用虚拟环境
source deactivate
要删除虚拟环境,请执行
conda remove -n envname -all
来源:
https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/
http://conda.pydata.org/docs/_downloads/conda-pip-virtualenv-translator.html
http://www.numericalexpert.com/blog/conda_virtual_environments/
http://stiglerdiet.com/blog/2015/Nov/24/my-python-environment-workflow-with-conda/