How to install two versions of Anaconda (Python 2 and 3) on Mac OS
Asked Answered
P

3

179

I'm relatively new in macOS. I've just installed XCode (for c++ compiler) and Anaconda with the latest Python 3 (for myself). Now I'm wondering how to install properly second Anaconda (for work) with Python 2?

I need both versions to work with iPython and Spyder IDE. Ideal way is to have totally separate Python environments. For example, I wish I could write like conda install scikit-learn for Python 3 environment and something like conda2 install scikit-learn for Python 2.

Poulterer answered 25/6, 2014 at 9:57 Comment(1)
The solution below seems to work well for me in Ubuntu as well. While Linux users should know well enough that a solution for Mac is worth trying on Linux as well, I recommend that you remove the osx and Mac tags from your title and replace with general "Unix". That way it will come up in more search results and/or not be ignored by Linux users. Especially if they are new to Linux or just don't know that Mac is Unix based.Padnag
W
332

There is no need to install Anaconda again. Conda, the package manager for Anaconda, fully supports separated environments. The easiest way to create an environment for Python 2.7 is to do

conda create -n python2 python=2.7 anaconda

This will create an environment named python2 that contains the Python 2.7 version of Anaconda. You can activate this environment with

source activate python2

This will put that environment (typically ~/anaconda/envs/python2) in front in your PATH, so that when you type python at the terminal it will load the Python from that environment.

If you don't want all of Anaconda, you can replace anaconda in the command above with whatever packages you want. You can use conda to install packages in that environment later, either by using the -n python2 flag to conda, or by activating the environment.

Westward answered 25/6, 2014 at 18:7 Comment(16)
Thanks! Can I run two Spider IDE's with IPythons on Python 2.7 and Python 3.4 simultaneously that way?Poulterer
I believe so. I'm quite certain, though, because I'm not sure how it will handle the user settings, which are stored outside of the environment.Westward
Great! Everything works just fine: both IDE runs in parallel. However, I still have no idea how to run two IPythons in browser.Poulterer
Start one ipython notebook from one terminal, then open another one, activate the other environment, and start the other.Westward
Each ipython notebook sets up another port (localhost:8888, localhost:8889, etc.). So just keep them straight and you're all set.Dobbins
Then how can I switch between python2 and python3? And BTW, I'm on win7.Danley
On Windows don't use source. It's just activate python2 and deactivate.Westward
This may not be the proper forum, but: I've followed these steps with mostly successful operations. However two things strike me as odd: 1) opening an IPython nb with a Python2 kernel allows me to use Python 2 or 3. Second, Spyder will not use python2 at all. Even when I launch from python2, it will still run python3.Bowshot
Where is python3.4 installed? I am tryin ot set up both versions in pycharm and I can't find where 3.4 is.Willis
@cmarti1138 the one you installed initially will be the anaconda directory, and the environments will be in anaconda/envs.Westward
yes... there will be two kernel engines one for each.. at the time of jupyter notebook start, it will load both the kernels... so all you have to do is to select appropriate kernelsAcross
best is to create separate environments for each.. such as .. one for 2.7 and another for 3.5 and then work from respective environmentAcross
When I did like this, (python2) is shown in my ubuntu terminal. Like (python2) shyamkkhadka@hp $ . How can I remove that (python2) ?Meter
@Meter that is there to show you that you've activated a conda environment. If you don't like it you can disable it with conda config --set changeps1 false.Westward
note that using just conda create -n python2 python=2.7 (as suggested on the website of anaconda) does not work wellLackadaisical
Hi @asmeurer. Thanks for your answer. Giving that as a fact, then what is the meaning of separating conda2 with conda3? What is the main differencePea
F
32

Edit!: Please be sure that you should have both Python installed on your computer.

Maybe my answer is late for you but I can help someone who has the same problem!

You don't have to download both Anaconda.

If you are using Spyder and Jupyter in Anaconda environmen and,

If you have already Anaconda 2 type in Terminal:

    python3 -m pip install ipykernel

    python3 -m ipykernel install --user

If you have already Anaconda 3 then type in terminal:

    python2 -m pip install ipykernel

    python2 -m ipykernel install --user

Then before use Spyder you can choose Python environment like below! Sometimes only you can see root and your new Python environment, so root is your first anaconda environment!

Anaconda spyder Python 2.7 or 3.5

Also this is Jupyter. You can choose python version like this!

Jupyter Notebook

I hope it will help.

Feriga answered 26/2, 2017 at 23:26 Comment(1)
Anaconda would need to be setup and configured for Jupyter kernels or Spyder before the specific libraries could be used from those options, though.Salina
M
4

This may be helpful if you have more than one python versions installed and dont know how to tell your ide's to use a specific version.

  1. Install anaconda. Latest version can be found here
  2. Open the navigator by typing anaconda-navigator in terminal
  3. Open environments. Click on create and then choose your python version in that.
  4. Now new environment will be created for your python version and you can install the IDE's(which are listed there) just by clicking install in that.
  5. Launch the IDE in your environment so that that IDE will use the specified version for that environment.

Hope it helps!!

Maramarabel answered 18/4, 2018 at 9:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.