Install and Use Both Python 2 and Python 3 in Windows with Anaconda – Python Tutorial

By | December 27, 2020

Python 2 and Python 3 is different, if you want to install and use both of them to programming, we will recommend anaconda to implement. In this tutorial, we will introduce how to do.


Install Anaconda in windows, you can download it at here.

Anaconda Python/R Distribution

anaconda download

Both anaconda python 3.7 and python 2.7 can be selected and installed on windows system, you select one of them.

After you have installed anaconda, such as 2.7 version, you can set up python 2.7 and python 3.5 environment.

Set up python 2.7 environment

open cmd 

conda create --name py2 python=2.7

anaconda python 2.7 environment

After you have set up python 2.7, you can know this environment

conda info --envs

anaconda python 2.7 environment infomation

If you want to use python 2.7, such as install some library, you shoud activate it.

Activate python 2.7

activate py2

if you are using linux or mac, you can use:

source activate py2

activate python 2.7

Then you can start to progam based on python 2.7.

If you do not want to use python 2.7, you can deactivate it.

Deactivate python 2.7

deactivate py2

on linx or mac, you can use:

source deactivate

Set up python 3.5

Similar to set up python 2.7, we can also set up a python 3.5 environment.

conda create --name py3 python=3.5

anaconda python environment

Then we can activate it.

activate py3

on linux or mac.

source activate py3

If you do not want to use python 3.5, you also can deactivate it like python 2.7.

Then we have installed python 2.7 and 3.5 in our computer. However, how to switch them? Here we will use Eclipse+PyDev for an example.

How to swith python version in Eclipse?

Open Python Interpreters

python interpreters

Add pyhon 2.7 and python 3.5

python 2.7 interpreters

Then you can get this result:

python 2.7 and 3.5 interpreters

We write an example to test python version and path.

import sys
print (sys.executable)

If path.exe is above, you will get result:

3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:05:27) [MSC v.1900 64 bit (AMD64)]

Change the order of python 3.5 and python 2.7.

python 3.5 and 2.7 interpreters

Then you will get result:

2.7.16 |Anaconda, Inc.| (default, Mar 14 2019, 15:42:17) [MSC v.1500 64 bit (AMD64)]