How to Install 2 Anacondas (Python 2 and 3) on MAC Os

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

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.

Is it ok having both Anacondas 2.7 and 3.5 installed in the same time?

My understanding is you don't need to install Anaconda again to start using a different version of python. Instead, conda has the ability to separately manage python 2 and 3 environments.

Manage both anaconda 2 and anaconda 3 distributions independently

If you have some legacy projects that run on Python 2.7, that does not mean that you should have Anaconda 2 and 3 installed at the same time. Although this shouldn't cause any significant problems, it can be confusing and irritating to deal with environment variables and whatnot. (I may be wrong on this - there may be compatibility problems that I am unaware of!)

Instead, what I recommend is to install only Anaconda 3 and use conda's virtual environments. Virtual environments allow you to create an independent project environment with different pip packages, package versions, and most of all different Python versions. Anaconda supports virtual environments in conda, and you can easily make a Python 2.7 environment in the console with

conda create -n Python27 python=2.7

This will create a virtual environment with the name of Python27 that runs Python 2.7, and you can run and manage all your legacy projects within this environment. That includes running files, Spyder, Jupyter Notebook, etc. You can activate this environment with:

source activate Python27

Even if you find a workaround for your problem with different Anaconda distributions for now, ultimately you will be using virtual environments. So I recommend doing so right now!

EDIT: The official Anaconda documentation also explicitly mentions conda environments as a way to install multiple versions of Python.

Easiest way to have Python 2 and 3 coexist on Mac OSX 10.8 with Anaconda installed

This sort of thing is actually what Anaconda is built for. Although the default Python version depends on the installer you used, Anaconda supports both versions. The easiest way is to create a new virtual environment. From the following link, use this conda command to build a Python 3 environment:

conda create -n py35 python=3.5 anaconda

That is if you need Python 3.5 with all the anaconda packages. You can either leave that blank if you just want a vanilla version of Python 3.5, or specify individual packages.

Once you do this, Python 3.5 will be available with the console command py35. You should definitely read the following link about how to manage environments. Really, you should read that whole tutorial.

how to create a separate python 2.7 environment in conda?

According to the documentation here, this should create a python2.7 virtual environment (29 April 2021) with spyder installed. I verified that spyder version 3.3.6 is python2.7 compatible

conda create -y -n py27 python=2.7 spyder=3.3.6

However, I could not run spyder in the py27 environment due to conflicts that conda failed to catch. The workaround shown by asanganuwan on this Spyder Github Issue page worked for me also

Found a workaround to use Spyder on python 2.7.

setup two virtual environments for Python 2.7 and 3.6.
Launce anaconda navigator and install spyder 3.3.6 on both the environments
Launch spyder on the environment with Python 3.6
Preferences-->Python Interpreter --> set the Python path for 2.7
Restart Spyder
Done!

So my recommendation is next run

conda create -y -n py36 python=3.6 spyder=3.3.6
conda activate py36
spyder

And follow the last three instructions from asanganuwan.

Also you should use the conda package manager as much as possible since it is smarter with managing requirements. When I try to use pip install spyder after activating the environment, it warns of version conflicts and fails to start.



Related Topics



Leave a reply



Submit