11

I currently have continuum analytics' Python distribution (called Anaconda) downloaded and in use on my computer. My problem is that I want to use virtualenv for a flask project and Anaconda flashes a warning that says "virtual env is not supported".

Is there any way I can run two distributions, stock Python and Anaconda on the same computer?

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
metersk
  • 11,803
  • 21
  • 63
  • 100
  • The reason virtualenv is not recommended is that conda environments are much better. `conda create -n envname flask`. – asmeurer Dec 06 '13 at 00:54

3 Answers3

19

Sure, if you want to use the Anaconda distribution separately, you can set up an alias to run that version and leave the stock python as the default.

In your .bash_profile file, the Anaconda installer probably put the following line:

export PATH="/path/to/your/anaconda/bin:$PATH"

Comment this out, and add an alias; e.g.

alias pyconda='/path/to/your/anaconda/bin/python'

You can then run your Anaconda python distribution by running pyconda in a new terminal.

update

It'd actually probably be better to put everything in the anaconda install into your path when you'd like to use it instead of just python (this is why your ipython broke initially).

To do this, set up an alias such as the following:

alias anacondainit='export PATH="/path/to/your/anaconda/bin:$PATH"'

Then your anaconda install will be the default for everything in that terminal session.

For instance, after opening up a new terminal, try the following:

amorgan$ python # on a freshly opened terminal, this will load your default distro
Python 2.7.2 |EPD 7.2-1 (32-bit)| (default, Sep  7 2011, 09:16:50)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "packages", "demo" or "enthought" for more information.
>>> exit()

amorgan$ anacondainit #initialize anaconda
amorgan$ python #now when we run python, it will load the anaconda distro
Python 2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Nov 11 2013, 10:49:09)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

To use your other distribution again, just load up a new terminal, thus getting anaconda out of your path.

qmorgan
  • 4,794
  • 2
  • 19
  • 14
  • i actually have another question: when I pip install something how to i know which distro it is going to and how do i force it to go to one or the other?? – metersk Dec 04 '13 at 01:16
  • I believe pip will by default install system-wide, unless you specify where you'd like the package to install. You can however install something only in your Anaconda distribution using the `conda` command; for instance, `conda install flask` will install the flask module in your Anaconda distribution, and `conda update flask` will update it. – qmorgan Dec 04 '13 at 01:27
  • Regarding ipython, one option would be to set up another alias (`alias ipyconda='/path/to/your/anaconda/bin/ipython'`) but upon reflection it'd probably be better to add everything in anaconda to your path should you want to use it. I've updated my answer above to reflect how to do this. – qmorgan Dec 04 '13 at 01:35
  • i'm unable to use the stock distribution - i type anacondainit and open a new terminal but nothing happens. i just get an endless prompt – metersk Dec 04 '13 at 01:41
  • I'm not quite sure what you mean, but I've added an example to hopefully clarify things. – qmorgan Dec 04 '13 at 01:54
1

What about using a version manager like pyenv?

Once installed, you can use it to install multiple python versions:

pyenv install 2.7.16
pyenv install anaconda-1.8.0

Then switch to a specific version locally or globally:

pyenv global 2.7.16

This blog has more details on this approach.

Ahmad Abdelghany
  • 11,983
  • 5
  • 41
  • 36
0

I guess the python is the same. What different is packages.

I use root lib of anaconda. I create ANACONDA=/path/to/anaconda environment variable and use anaconda packages if the variable is defined:

# if You want to run the script in anaconda - export ANACONDA=/path/to/anaconda
import os
try:
    os.environ["ANACONDA"]
    sys.path.insert(1, os.environ["ANACONDA"] + "/lib/python2.7/site-packages")
except KeyError:
    pass
Adobe
  • 12,967
  • 10
  • 85
  • 126