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?
pip is the standard package manager for python, meaning you can use it both inside and outside of Anaconda.
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.
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$"
To activate a virtual environment then do:
source activate envname
To install packages to your new virtual environment type
conda install -n envname [package]
To deactivate a virtual environment do
source deactivate
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With