ChatGPT解决这个技术问题 Extra ChatGPT

How to install 2 Anacondas (Python 2 and 3) on Mac OS

I'm relatively new in Mac OS. 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.

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.

a
asmeurer

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.


Thanks! Can I run two Spider IDE's with IPythons on Python 2.7 and Python 3.4 simultaneously that way?
Each ipython notebook sets up another port (localhost:8888, localhost:8889, etc.). So just keep them straight and you're all set.
Then how can I switch between python2 and python3? And BTW, I'm on win7.
On Windows don't use source. It's just activate python2 and deactivate.
@Shyamkkhadka 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.
A
Axis

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!

https://i.stack.imgur.com/AIUqg.png

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

https://i.stack.imgur.com/imJrG.png

I hope it will help.


Anaconda would need to be setup and configured for Jupyter kernels or Spyder before the specific libraries could be used from those options, though.
D
David

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.

Install anaconda. Latest version can be found here Open the navigator by typing anaconda-navigator in terminal Open environments. Click on create and then choose your python version in that. 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. Launch the IDE in your environment so that that IDE will use the specified version for that environment.

Hope it helps!!