10

Im trying to switch between python versions 3.6.6 and 3.7.0 in windows. I tried py -3.6.6 and doesn't work. Looked for options in py -h, found none. I saw a couple of answers for switching between python versions 2.x and 3.x by adding #!python3 at the start of the file.

I'm able to switch between these by moving path variables up and down but I want to know if there is a option to switch between versions in cmd like there is brew switch python version in IOS.

Thank you.

Tarun Kolla
  • 917
  • 1
  • 10
  • 30

4 Answers4

13

If You have python of the same version with different subversion e.g. 2.6, 3.7,.. 3.9.
Use the below command to open specific python version's terminal in command prompt:

py -2.6
py -3.7
.

for installing modules in command prompt:

py -2.6 -m pip install <modules>
py -3.7 -m pip install <modules>
NevetsKuro
  • 604
  • 7
  • 14
3

The easiest way is simply type py -2 if you want to use python2, and py -3 if you want to use python3.

Hoppo
  • 1,130
  • 1
  • 13
  • 32
Zhe Huang
  • 31
  • 1
2

Change the path in environment variable after downloading python 3.7.0 in windows where you can find in the properties of My Computer in Advanced System Settings

Akash Badam
  • 476
  • 2
  • 9
2

If you need to use multiple versions of Python, or run different sets of packages in the Python environment, you should probably just use Anaconda to create them, for example:

    conda create -n py36 python=3.6 anaconda

then you can just switch between them using

    activate <your-environment-name>
  • I'm not into anaconda but does `conda create -n py36 python=3.6 anaconda` create a virtual environment? – Tarun Kolla Sep 02 '18 at 05:28
  • Yes, if you first install Anaconda, it will have a default python environment, but typically you'd want to set up a separate environment with whatever version of python plus a set of packages needed for your task that also match the version for that environment. The "-n py36" creates a new python environment called "py36", you can call it anything you like. The "python=3.6" is which version of the python interpreter to use. The "anaconda" and anything else is to select which packages to install in the newly created environment. – Ho John Lee Sep 02 '18 at 18:44