Installing Anaconda into a Virtual Environment
Solution 1
I just tested the Anaconde 1.6 installer from http://continuum.io/downloads
After downloading, I did:
bash Anaconda-1.6.0-Linux-x86_64.sh
If you take the defaults, you'll end up with a directory anaconda
in your home directory, completely separate from your EPD or system Python installation.
To activate the anaconda installation's default environment, do the following:
source $HOME/anaconda/bin/activate ~/anaconda
All Python commands will now come from the default Anaconda environment in $HOME/anaconda
, which is itself a kind of a virtual environment. You can create sub-environments with e.g. conda create -n myenv1 ipython scipy
, but this is not necessary.
As a side note, you can also use pip
(also in $HOME/anaconda/bin
) to install PyPI packages into your Anaconda default environment (it has pip
installed by default) or any of the sub-environments (in which case you should first install pip
into the sub-environment using conda install -n myenv1 pip
).
It is possible to install parts of Anaconda manually into an existing virtualenv, but using their installer is by far the easiest way to test and use, without affecting any of your existing Python installations.
Solution 2
When you create your virtualenv use the -p
flag to give it the path to the Python executable you want to use:
virtualenv -p /path/to/python-anaconda-version
Fomite
Infectious disease epidemiologist specializing in the intersection between mathematical models of disease transmission and observational methods. Crafter of artisanal simulation models for the discerning scientist. Oddly fond of enteric pathogens. A fair hand at SAS, Python and R @GermsAndNumbers
Updated on October 24, 2020Comments
-
Fomite over 3 years
I've currently got a working installation of the Enthought Python Distribution on my machine that I don't want to necessarily disrupt, but I'd like to look at moving over to Anaconda from Continuum.
I can easily install Anaconda into the virtualenv directory I create, but I'm not sure how to tell that virtualenv to use the anaconda-version of Python. If I was telling my whole system to use it I can alter
.bash_profile
with something likeexport PATH="/DIRECTORIES/anaconda/bin:$PATH
. Is there a way to do that within a virtualenv? -
Fomite almost 11 yearsIncidentally, version 1.6 broke this, and will produce a "No Environment Specified" error. This can be fixed by providing an environment after activate, including a general 'source $home/anaconda/bin/activate ~/anaconda'
-
Charl Botha almost 11 yearsThanks for the comment! I just updated my answer. Coincidentally, I also discovered this during the making of a Python tutorial screencast a few days ago: youtube.com/… :)
-
KLDavenport over 10 yearsUsing root on CentOS, will making a change to .bashrc break the system's Python which will break things like yum that rely on an older version of Python?
-
Charl Botha over 10 yearsroot's .bashrc only affects the root account, just like any other user's .bashrc affects only that user account.
-
drevicko over 8 yearsOn OsX (at least with osx 10.10.5, anaconda3 2.4.1) this doesn't work: virtualenv doesn't like anaconda's python executable (something about sys.prefix being unexpected).
-
Admin over 7 yearsSame problem with anaconda3 3.4 on ubuntu 16.04. I get that error about sys.prefix. No error on windows 10, however.
-
Carmine Tambascia almost 6 yearsFor Anaconda3 5.2.0 ~/anaconda after source activate is not necessary anymore