Using tox with Anaconda pioneer

On an Ubuntu system, I am trying to test a python package with tox and multiple python versions. One of the python versions I'm trying to test is the 64-bit Anaconda Python 2.7. Before I can start testing with Tox, I first need to get virtualenv to work with Anaconda, because Tox uses virtualenv internally.

As you can see, virtualenv is already installed in my Anaconda environment:

$ 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 

However, an attempt to create a virtual environment fails:

 $ 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 

How to get virtualenv to work with Anaconda?

+6
source share
1 answer

I see that it’s too late to answer this, and you probably solved it ... but there is still no answer to this question, so I will give it anyway! I will give a recipe that can be found on other sites, and I have listed various sources so that if the links break the answer, you can still see it here.

First of all, mkvirtualenv is a command defined by virtualenvwrapper, not just virtualenv.
Secondly, the path (commands) for creating a virtual environment using python Anaconda is different from the standard python with virtualenv installed.

Creating a virtual environment

Using anaconda python to create a virtual file, create the following sequence:

 conda create -n envname python=xx anaconda 

where envname is the name of your virtual environment, and you got the python version you want to use as follows:

 conda search "^python$" 

Activate virtual environment

To activate the virtual environment, follow these steps:

 source activate envname 

Installing packages in a virtual environment

To install packages in a new type of virtual environment

 conda install -n envname [package] 

Deactivate a virtual environment

To disable the virtual environment, do

 source deactivate 

Removing a virtual environment

To remove the virtual environment, do

 conda remove -n envname -all 

Sources:
https://uoa-eresearch.imtqy.com/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/

0
source

All Articles