37

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 like export PATH="/DIRECTORIES/anaconda/bin:$PATH. Is there a way to do that within a virtualenv?

nbro
  • 15,395
  • 32
  • 113
  • 196
Fomite
  • 2,213
  • 7
  • 30
  • 46

2 Answers2

36

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.

nbro
  • 15,395
  • 32
  • 113
  • 196
Charl Botha
  • 4,373
  • 34
  • 53
  • 3
    Incidentally, 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' – Fomite Jul 03 '13 at 00:03
  • Thanks 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: http://www.youtube.com/watch?v=NwyIuWK80gQ&feature=share&list=UUaSstndBFlz3J8quggQ8APw :) – Charl Botha Jul 03 '13 at 08:34
  • Using 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? – KLDavenport Jan 16 '14 at 21:19
  • root's .bashrc only affects the root account, just like any other user's .bashrc affects only that user account. – Charl Botha Jan 18 '14 at 07:50
  • For Anaconda3 5.2.0 ~/anaconda after source activate is not necessary anymore – Carmine Tambascia Jun 06 '18 at 08:51
5

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
nbro
  • 15,395
  • 32
  • 113
  • 196
alexhb
  • 435
  • 2
  • 12
  • 4
    On 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). – drevicko Jan 12 '16 at 11:25
  • 2
    Same problem with anaconda3 3.4 on ubuntu 16.04. I get that error about sys.prefix. No error on windows 10, however. –  Jan 28 '17 at 20:07