Using tox with Anaconda python
Asked Answered
F

1

8

On an Ubuntu system, I'm attempting to test a python package with tox and multiple python versions. One of the python versions I am trying to test is 64-bit Anaconda Python 2.7. Before I can begin testing with Tox, I first need to get virtualenv working 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, attempting 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 working with Anaconda?

Fardel answered 30/10, 2015 at 12:47 Comment(3)
Is there a particular benefit to using a virtualenv instead of a conda environment?Dumont
@DilithiumMatrix, tox is an automatic testing tool that automatically generates virtualenvs. Asking for the benefit does not really make sense, since you have no option :)Thyestes
Do you have to use anaconda in the first place?Nor
D
1

I see it's late to answer this and you probably solved it...but still there's no answer so I will give one anyway here! I will give the recipe that can be found in other websites and I will list various sources so that if the links break the answer can still be seen here.

First of all, mkvirtualenv is a command defined by the package virtualenvwrapper and not just virtualenv.
Second, the way (the commands) to create a virtual environment with Anaconda python is different than standard python with virtualenv installed.

Create a virtual environment

With Anaconda python, to create a virtualenv one should follow the following sequence to create one:

conda create -n envname python=x.x anaconda

where envname is the name of your virtual environment and you have retrieved the python version you want to use via the following:

conda search "^python$"

Activate a virtual environment

To activate a virtual environment then do:

source activate envname

Installing packages to a virtual environment

To install packages to your new virtual environment type

conda install -n envname [package]

Deactivate a virtual environment

To deactivate a virtual environment do

source deactivate

Delete a virtual environment

To delete a virtual environment do

conda remove -n envname -all  

Sources:
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/

Dwightdwindle answered 23/12, 2016 at 19:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.