249

I had two versions of Python installed on my machine (versions 2.6 and 2.5). I want to run 2.6 for one project and 2.5 for another.

How can I specify which I want to use?

I am working on Windows XP SP2.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Bilal Basharat
  • 3,066
  • 6
  • 21
  • 20
  • 4
    Good hints for asking questions is to explain what you have tried, and in what way that failed. So: What did you try, and in what way did that not work? – Lennart Regebro Jan 03 '11 at 10:02
  • Note, I couldn't find any previous questions about this on Windows, so I changed the title to reflect that. – Lennart Regebro Jan 03 '11 at 10:02
  • 1
    Related: [Official multiple python versions on the same machine?](http://stackoverflow.com/q/2547554/95735) – Piotr Dobrogost Aug 27 '14 at 21:10
  • If you want to run 3.3 along with 2.7 then this is the most *standardized* answer:- http://stackoverflow.com/questions/15912063/how-do-i-run-python-2-and-3-in-windows-7/17245543#17245543 – Omar Tariq Jul 12 '15 at 16:37

25 Answers25

178

Running a different copy of Python is as easy as starting the correct executable. You mention that you've started a python instance, from the command line, by simply typing python.

What this does under Windows, is to trawl the %PATH% environment variable, checking for an executable, either batch file (.bat), command file (.cmd) or some other executable to run (this is controlled by the PATHEXT environment variable), that matches the name given. When it finds the correct file to run the file is being run.

Now, if you've installed two python versions 2.5 and 2.6, the path will have both of their directories in it, something like PATH=c:\python\2.5;c:\python\2.6 but Windows will stop examining the path when it finds a match.

What you really need to do is to explicitly call one or both of the applications, such as c:\python\2.5\python.exe or c:\python\2.6\python.exe.

The other alternative is to create a shortcut to the respective python.exe calling one of them python25 and the other python26; you can then simply run python25 on your command line.

Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366
aodj
  • 2,163
  • 1
  • 12
  • 13
  • 72
    how to create that shortcut – Bilal Basharat Jan 04 '11 at 06:11
  • 10
    When you're in windows, navigate to the folder that contains the python version you want to create a shortcut for, then right click and create shortcut. You can then rename it. – aodj Jan 04 '11 at 10:29
  • 5
    Sorry to dig up a long dead post, but how will you make the shortcut work without requiring the .lnk extension? – Nathan Tornquist Oct 30 '11 at 20:52
  • 2
    @NathanTornquist - I was just trying to figure out the same problem, the best I could come up with is making copies of the executables and renaming them instead of creating shortcuts. – Andrew Clark Nov 10 '11 at 17:44
  • 8
    If a shortcut doesn't work, you can do as @F.J said, and simply copy and rename. Failing that, you can make a symbolic link, using ''mklink'' on the command line. – aodj Nov 13 '11 at 13:34
  • @F. J. I ended up creating shortcuts for the python files with the names that I wanted to show up in command prompt, then I added the .lnk extension to the path so that shortcuts worked as commands in command prompt. – Nathan Tornquist Dec 01 '11 at 21:38
  • The solution would be to use hard links using the /H switch of mklink. You can't just copy and paste the links that way though. – Sebastian Graf Nov 16 '12 at 17:59
  • 8
    Wouldn't the best way be to create a bat file called python25 and python26 and make those call the appropriate version? Then all you would need to do is put those 2 bat files alongside their binaries. – Jeremy Cantrell Jan 29 '13 at 16:05
  • The mklink solution is posted a couple answers down the page. I am using it and have been very happy with it. – meawoppl Jan 24 '14 at 18:35
  • 1
    You can add .ink to the environment variable PATHTEXT to avoid typing ink. Or, you can just add .exe (case sensitive), copy python.exe as python34.exe. – Tycon Jul 19 '15 at 02:00
  • 1
    how can I install libraries with pip for a particular version of python?? – yeahman Nov 01 '19 at 05:55
  • @JeremyCantrell - Good solution for eliminating the need for the extension, but how can you run a **.py** file using that? If you type `python35 myfile.py`, it will go into the python console and ignore `myfile.py` – Alaa M. Jan 13 '20 at 11:47
  • 1
    @AlaaM. Not if you pass the command line arguments to the python command in the script using %* – Jeremy Cantrell Feb 29 '20 at 19:06
  • @JeremyCantrell - Can you elaborate on this? How do you run the script using the bat file? – Alaa M. Jun 03 '20 at 07:27
  • 2
    @AlaaM. Inside the bat file, you'll need to call the python executable like this: `c:\path\to\python.exe %*`. The `%*` causes any arguments given to the bat file to be passed along to the python interpreter. – Jeremy Cantrell Aug 08 '20 at 00:34
  • 1
    Simply creating a shortcut as @aodj recommended did not work for me. I followed [these instructions here](https://levelup.gitconnected.com/install-multiple-python-versions-on-windows-10-15a8685ec99d). Namely, the "Copy the Executable File" section (and the one right before it, to change directories in PowerShell) did something else that was also required to make a copy of the executable with a different name. Works perfectly now. (Don't forget to setup your PATH as well) – Vinícius Queiroz Dec 09 '21 at 21:21
152

Adding two more solutions to the problem:

  • Use pylauncher (if you have Python 3.3 or newer there's no need to install it as it comes with Python already) and either add shebang lines to your scripts;

#! c:\[path to Python 2.5]\python.exe - for scripts you want to be run with Python 2.5
#! c:\[path to Python 2.6]\python.exe - for scripts you want to be run with Python 2.6

or instead of running python command run pylauncher command (py) specyfing which version of Python you want;

py -2.6 – version 2.6
py -2 – latest installed version 2.x
py -3.4 – version 3.4
py -3 – latest installed version 3.x

virtualenv -p c:\[path to Python 2.5]\python.exe [path where you want to have virtualenv using Python 2.5 created]\[name of virtualenv]

virtualenv -p c:\[path to Python 2.6]\python.exe [path where you want to have virtualenv using Python 2.6 created]\[name of virtualenv]

for example

virtualenv -p c:\python2.5\python.exe c:\venvs\2.5

virtualenv -p c:\python2.6\python.exe c:\venvs\2.6

then you can activate the first and work with Python 2.5 like this
c:\venvs\2.5\activate
and when you want to switch to Python 2.6 you do

deactivate  
c:\venvs\2.6\activate
Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366
  • 1
    pylauncher appears to be a prototype implementation of [PEP 397](http://www.python.org/dev/peps/pep-0397/) which was Accepted as Standards Track way back in 2011. Do you know why the launcher still isn't being distributed with Python for Windows or why there's still only Vinay Sajip's prototype implementation? – martineau Jan 02 '13 at 04:58
  • 4
    Pylauncher is being distributed with Python starting from version 3.3 - see http://www.python.org/download/releases/3.3.0/. Also I think Vinay Sajip's implementation is the implementation not merely a prototype. – Piotr Dobrogost Jan 02 '13 at 10:02
  • 1
    Thank you for the clarification. IMHO pylauncher should be distributed as part of the latest Python 2 version too because people using that version are more likely to the ones wanting to install multiple versions (and be more likely to do so if they were aware of its functionality and availability). – martineau Jan 02 '13 at 16:42
  • StackOverflow should allow multiple upvotes, your answer deserves infinite upvotes! Seriously where have you been bro! :D Simple, Clear and working of course! – 3bdalla Jul 13 '15 at 14:32
  • Very good suggestions. I used the second (virtualenv) one. Only difference I found was I had to include '\scripts' in the path to activate, eg: `c:\venvs\2.5\scripts\activate`. This is on Windows 10 if that makes a difference. Other than that, works like a charm, thanks. – Dave Marley Feb 18 '20 at 19:25
  • 2
    Slightly nicer: Write the shebang lines UNIX-style; the launcher knows how to parse them. So `#!/usr/bin/env python2.7` will find the latest 2.7 interpreter installed when run with `py.exe`, with no additional arguments required. – ShadowRanger Jan 28 '21 at 03:32
60

From Python 3.3 on, there is the official Python launcher for Windows (http://www.python.org/dev/peps/pep-0397/). Now, you can use the #!pythonX to determine the wanted version of the interpreter also on Windows. See more details in my another comment or read the PEP 397.

Summary: The py script.py launches the Python version stated in #! or Python 2 if #! is missing. The py -3 script.py launches the Python 3.

Community
  • 1
  • 1
pepr
  • 20,112
  • 15
  • 76
  • 139
  • 2
    This is the answer I'm looking for. I run Windows 10 with Python 2.7 and Python 3.4.3. In command prompt type in "py [python_version_number]" ex: py -3 or py will invoke the python version you have. I think environment variables must be set before you use this. this is convenient for me. – CodeMonkey Mar 12 '16 at 12:57
  • 3
    @Inuka: No environment variables need to be set. The Python installer sets the associations with the `.py` extension. The launcher itself is installed into `C:\Windows` that is already in the `PATH`. This way, also the `PATH` variable need not to be modified. – pepr Mar 14 '16 at 12:49
  • 3
    Thanks a lot for your answer mate. From this way we can invoke the pip as well. py -2 -m pip install SomePackage or py -3.4.3 -m pip install SomePackage – CodeMonkey Mar 14 '16 at 17:15
  • 1
    I think this the most simple and no fuss solution. – prasad May 19 '16 at 19:39
  • Thanks! the comments have been really helpful. How do I activate a virtual environment with one of the python versions I have using pipenv? – omokehinde igbekoyi Sep 15 '20 at 08:31
  • I used pipenv --python 3.7 to set the python version – omokehinde igbekoyi Sep 15 '20 at 08:48
  • Perfect. I just tested it on my system, installing versions 3.6.13, 3.8.7 and 3.9.2. If I type `py foo.py`, it runs the latest version I have installed. I can type `py -3.8 foo.py` or `py -3.6 foo.py` to select one of the others. – David C. Feb 22 '21 at 17:57
  • @DavidC: Yes, the later versions launches the latest Python 3 version that is installed. At the time, Python 3 was rather new, and the latest Python 2 was the default to be launched. – pepr Apr 13 '21 at 19:32
  • `py -2 script.py` worked for me. – Vyk Sep 20 '21 at 23:02
59

As per @alexander you can make a set of symbolic links like below. Put them somewhere which is included in your path so they can be easily invoked

> cd c:\bin
> mklink python25.exe c:\python25\python.exe
> mklink python26.exe c:\python26\python.exe

As long as c:\bin or where ever you placed them in is in your path you can now go

> python25
Christopher Hackett
  • 6,042
  • 2
  • 31
  • 41
  • 4
    Clever idea. BTW `mklink` is only natively available in Windows Vista/2008+. On XP and Server 2003 a "hardlink" could be created instead using `fsutil hardlink create ` and putting or moving the to somewhere in your path. Hardlinks only work on the same drive, however. – martineau Jan 02 '13 at 05:21
  • This is a good solution, I am not sure it works without a NTFS based file system as well. – meawoppl Jan 24 '14 at 18:34
  • Yes, requires support for NTFS symbolic links which I believe was introduced in Vista (I may be wrong). Use on XP requires use of a [different driver](http://en.wikipedia.org/wiki/NTFS_symbolic_link#Symbolic_links_in_Windows_XP). Sounds like it was turned off at some stage before general release. – Christopher Hackett Jan 28 '14 at 11:54
  • easiest best solution – omushpapa Dec 28 '17 at 18:53
45

For example for 3.6 version type py -3.6. If you have also 32bit and 64bit versions, you can just type py -3.6-64 or py -3.6-32.

Mehran Jalili
  • 585
  • 7
  • 18
  • 4
    This should be the Accepted Answer! Thanks a ton! – Xonshiz Oct 29 '19 at 05:43
  • 3
    This is possibly the best answer, as it requires no renaming of files and third party IDEs will detect both as normal! – enchant97 Dec 08 '19 at 10:05
  • 2
    could you enhance the answer with more explanation - where is this `py` executable - is it a windows-only addition? Is it possible to incorporate this into a cross-platform command-line script which has at the top: `#!/usr/bin/env python3` for example? – Ed Randall Jun 10 '20 at 07:18
  • how can I then run for example jupyter notebook with version 3.8, when I have both 3.7 and 3.8? – Shilan Oct 15 '20 at 16:38
  • @Shilan you can proceed the same way as when calling pip when calling jupyter: `py -3.8 -m jupyter notebook` – Angel Auñón Nov 01 '20 at 12:33
  • @AngelAuñón but I only type “jupyter notebook” in the command line and it starts. I am not sure if it works if I run py ... – Shilan Nov 28 '20 at 07:38
  • 1
    @EdRandall my response is a bit late, but `py` is Py Launcher for Windows. Official documentation is here: https://docs.python.org/3/using/windows.html?highlight=pylauncher#python-launcher-for-windows and it includes support for shebangs. – Ray Depew May 03 '21 at 17:48
  • An example, to create a virtual environment that runs a specific (installed) version of Python: `py -3.7 -m venv myEnvs\three7` – Ray Depew May 03 '21 at 17:53
22
  1. install python

    • C:\Python27
    • C:\Python36
  2. environment variable

    • PYTHON2_HOME: C:\Python27
    • PYTHON3_HOME: C:\Python36
    • Path: %PYTHON2_HOME%;%PYTHON2_HOME%\Scripts;%PYTHON3_HOME%;%PYTHON3_HOME%\Scripts;
  3. file rename

    • C:\Python27\python.exe → C:\Python27\python2.exe
    • C:\Python36\python.exe → C:\Python36\python3.exe
  4. pip

    • python2 -m pip install package
    • python3 -m pip install package
山茶树和葡萄树
  • 2,050
  • 1
  • 18
  • 18
  • I think, more or less this is the practical solution for the question. This is more handy compared with the approach where shortcut / symbolic link is used to call the python script. Instead of renaming the file, we can copy & paste the binary (python.exe) then rename it according to it's version (as shown in this answer). By the way, `python` command would be confusing to OS. – testuser Jan 06 '20 at 00:29
  • Great answer! Thanks~@山茶树和葡萄树 – Bright Chang Jun 15 '20 at 15:18
  • This is a mimic to the way it is done on Unix systems - multiple python executables with version-specific names. But it requires hacking the installation on Windows. The Python launcher (see other comments) is easier for the rest of us - especially those not familiar with Unix installations. – David C. Jul 12 '21 at 14:35
  • 我真他媽的服了! 這回答簡直是鬼才邏輯! 讚! – W Kenny Apr 02 '23 at 14:30
13

I strongly recommend the pyenv-win project.

enter image description here

Thanks to kirankotari's work, now we have a Windows version of pyenv.

Xin Lv
  • 171
  • 1
  • 3
11

One easy way for this is that you can use

py -3.8 -m pip install virtualenv here -3.8 goes with your [version number]

After installing the virtualenv, you can create the virtual environment of your application using

py -3.8 -m virtualenv [your env name]

then cd to venv, enter activate

This would activate the python version you like. Just change the version number to use a different python version.

Jithin Palepu
  • 596
  • 1
  • 7
  • 18
7

When you install Python, it will not overwrite other installs of other major versions. So installing Python 2.5.x will not overwrite Python 2.6.x, although installing 2.6.6 will overwrite 2.6.5.

So you can just install it. Then you call the Python version you want. For example:

C:\Python2.5\Python.exe

for Python 2.5 on windows and

C:\Python2.6\Python.exe

for Python 2.6 on windows, or

/usr/local/bin/python-2.5

or

/usr/local/bin/python-2.6

on Windows Unix (including Linux and OS X).

When you install on Unix (including Linux and OS X) you will get a generic python command installed, which will be the last one you installed. This is mostly not a problem as most scripts will explicitly call /usr/local/bin/python2.5 or something just to protect against that. But if you don't want to do that, and you probably don't you can install it like this:

./configure
make
sudo make altinstall

Note the "altinstall" that means it will install it, but it will not replace the python command.

On Windows you don't get a global python command as far as I know so that's not an issue.

martineau
  • 119,623
  • 25
  • 170
  • 301
Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • thanks for ure help plz answer my second question also: how can i run both at a time? as i successfully switched from 2.5 to 2.6 – Bilal Basharat Jan 03 '11 at 09:44
  • @Bilal Basharat: Windows is a multi-tasking OS if you want to run two things at the same time, you just start both, so I don't understand your question. – Lennart Regebro Jan 03 '11 at 09:48
  • currently i am working on python2.5. simply elaborate me how can i run 2.6 also ? when i write 'python' in windows command prompt to enter python shell than python2.5 appears. in c drive i had both version installed. when i go to C:\Python2.6\Python.exe. than python2.6 temporarily activated. as soon as i leave C:\Python2.6\ it again turned into version 2.5 – Bilal Basharat Jan 03 '11 at 10:38
  • 3
    @Bilal Basharat: I already answered this. It is not "temporarily activated". You ran Python 2.6 with the command C:\Python2.6\Python.exe and that is how you run it. And you run Python 2.5 with the command C:\Python2.5\Python.exe. That is how you run both at the same time. – Lennart Regebro Jan 03 '11 at 10:58
  • 1
    @Bilal Basharat: If either the `C:\Python2.5` or `C:\Python2.6` directory appears in your `PATH` environment variable, the corresponding version of Python will become the default *unless* you override it by explicitly specifying a different path to the .exe you wish to use. – martineau Jan 03 '11 at 15:24
5

Here's a quick hack:

  1. Go to the directory of the version of python you want to run
  2. Right click on python.exe
  3. Select 'Create Shortcut'
  4. Give that shortcut a name to call by( I use p27, p33 etc.)
  5. Move that shortcut to your home directory(C:\Users\Your name)
  6. Open a command prompt and enter name_of_your_shortcut.lnk(I use p27.lnk)
David Greydanus
  • 2,551
  • 1
  • 23
  • 42
2

cp c:\python27\bin\python.exe as python2.7.exe

cp c:\python34\bin\python.exe as python3.4.exe

they are all in the system path, choose the version you want to run

C:\Users\username>python2.7
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>>

C:\Users\username>python3.4
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Community
  • 1
  • 1
bruceyang
  • 57
  • 3
  • this worked for me. Just have to use copy instead of cp. Also when running this command you have to be somewhere on the path and both python installations e.g. c:\python34\bin\python.exe and c:\python27\bin\python.exe need to be in the path also . ( preferably in that order). – Gregor Jul 22 '17 at 14:56
2

The easiest way to run multiple versions of python on windows is described below as follows:-

1)Download the latest versions of python from python.org/downloads by selecting the relevant version for your system.

2)Run the installer and select Add python 3.x to the path to set path automatically in python 3 (you just have to click the checkbox). For python 2 open up your python 2 installer, select whatever preferences you want but just remember to set Add python.exe to path to Will be installed on local hard drive, Now just click next and wait for the installer to finish.

3)When both the installations are complete. Right click on my computer--Go to properties--Select advanced system settings--Go to environment variables--Click on new under System variables and add a new system variable with variable name as PY_PYTHON and set this variable value to 3. Now click on OK and you should be done.

4)Now to test this open the command prompt. Once you are in there type python or py, It should open up python3.

5)Now exit out of python3 by typing exit(). Now type py -2 it should open python 2.

If none of this works then restart the computer and if the problem still persists then uninstall everything and repeat the steps.

Thanks.

2

This is a simple and elegant solution to easily run 2 or more different versions of python without using scripts in Windows. Whatever the version of python, it will start from the Command prompt.

I have python versions 3.6.6 and 3.9. The Environment Variable paths are normal and were automatically added when each version of python was installed.

It's best to install python using the "all users" option. This way the python will simply install to:

C:\program files\python36  
C:\program files\python39

Open each of these python folders and find the python.exe file. Copy and paste the python.exe file into those same folders. Then carefully rename the copies to:

python36.exe
python39.exe

Open and edit Environment Variables. Add 4 new User Variables.

C:\Program Files\Python36\Scripts
C:\Program Files\Python36\python36.exe    
C:\Program Files\Python39\Scripts
C:\Program Files\Program39\python39.exe 

Save and exit Environment Variables.

Open a new Command Prompt terminal window. To run one or the other version of python, type:

python36

python39

More versions of python can easily be added by repeating the same as shown above. Elegant and simple. Done.

Gray
  • 1,164
  • 1
  • 9
  • 23
  • 1
    This is the answer!!!! omgosh thank you ... only caveat is regular `python --version` now calls most recent version instead of initially installed .... but totally fine! The key to this is having those original python files say python. If you just rename them, this doesn't work. – ProsperousHeart Jun 10 '22 at 21:06
2

Shows your installed pythons

py -0

Uses version of python to do something

py -*version*

ex.

py -3.8 venv venv

Will create virtual environment in python 3.8

Note:

python -0 
 or
python -3.8

doesn't work, I assume it has to be "py"

2

Here is a solution:

  1. First, install all versions which you want to run in your pc. https://www.python.org/
  2. Second, create virtual environment with which python version you want to use. "py [python_version] -m venv [vritual_environment_name]" example: "py -3.9 -m venv env"

Note: You don't need to run "pip install virtualenv"

rahat04
  • 21
  • 3
1

Using a batch file to switch, easy and efficient on windows 7. I use this:

In the environment variable dialog (C:\Windows\System32\SystemPropertiesAdvanced.exe),

In the section user variables

  1. added %pathpython% to the path environment variable

  2. removed any references to python pathes

In the section system variables

  1. removed any references to python pathes

I created batch files for every python installation (exmple for 3.4 x64

Name = SetPathPython34x64 !!! ToExecuteAsAdmin.bat ;-) just to remember.

Content of the file =

     Set PathPython=C:\Python36AMD64\Scripts\;C:\Python36AMD64\;C:\Tcl\bin

     setx PathPython %PathPython%

To switch between versions, I execute the batch file in admin mode.

!!!!! The changes are effective for the SUBSEQUENT command prompt windows OPENED. !!!

So I have exact control on it.

Aman
  • 11
  • 2
1

let's say if we have python 3.7 and python 3.6 installed.

they are respectively stored in following folder by default.

C:\Users\name\AppData\Local\Programs\Python\Python36 C:\Users\name\AppData\Local\Programs\Python\Python37

if we want to use cmd prompt to install/run command in any of the above specific environment do this:

There should be python.exe in each of the above folder.

so when we try running any file for ex. (see image1) python hello.py. we call that respective python.exe. by default it picks lower version of file. (means in this case it will use from python 3.6 )

image

so if we want to run using python3.7. just change the .exe file name. for ex. if I change to python37.exe and i want to use python3.7 to run hello.py

I will use python37 hello.py . or if i want to use python3.7 by default i will change the python.exe filename in python3.6 folder to something else . so that it will use python3.7 each time when I use only python hello.py

1

I have versions 3.11.3 and 3.10.11 and you can run different versions from powershell or cmd, stuff like that, just by typing python3.10 or python3.11 etc. Just make sure not to use python310 or python311 as it does not work. This is probably the most simple solution for your problem, in my opinion.

PD6152
  • 23
  • 8
0

You can create different python development environments graphically from Anaconda Navigator. I had same problem while working with different python versions so I used anaconda navigator to create different python development environments and used different python versions in each environments.

Here is the help documentation for this.

https://docs.anaconda.com/anaconda/navigator/tutorials/manage-environments/

mohitesachin217
  • 451
  • 5
  • 14
0

Introduce more details based on the answer given by @Aman. Define different environment variables for different python versions. For example:

  • You have E:\python2\python.exe and E:\python3\python.exe at the same time.
  • Then you can set an environment variable %python2% for E:\python2\python.exe and %python2% for E:\python3\python.exe.
  • Finally, when you want to run python2 (or python3), you can enter %python2% (or %python3%) directly in command prompt.
Qiu Junyan
  • 31
  • 2
0

In 2023

let's say previous python is 3.7 it has this paths in the environment variables set as

C:\Program Files\Python37\Scripts\

C:\Program Files\Python37\

Now let's say you install 3.10.* it has this paths in the environment variables set as

C:\Program Files\Python310\Scripts\

C:\Program Files\Python310\

What this means is that its added to path of where windows will look when you enter a command like python in the CMD and will select from the path that matches first

If you enter python it will return python for the first path it sees it executable in

Solution

So to call any python of your choice rename python executable in path C:\Program Files\Python310\ to python310 and call from CMD as python310 to use

python3.10

I.e if you call ordinary python in CMD it will return the other version that wasn't renamed which is 3.7 in my case

For Pip

just call

pip3.10

pip3.7

swifthmd
  • 1
  • 2
0

The simplest solution that worked for Windows 10:

Open Terminal

> cd Users\username\AppData\Local\Programs\Python
> copy python36\python.exe python36\python36.exe
> copy python39\python.exe python39\python39.exe

Now, running python36 in the Terminal will fire up python3.6 version and python39 will fire up python 3.9 version

chmodsss
  • 711
  • 8
  • 18
-1

Using the Rapid Environment Editor you can push to the top the directory of the desired Python installation. For example, to start python from the c:\Python27 directory, ensure that c:\Python27 directory is before or on top of the c:\Python36 directory in the Path environment variable. From my experience, the first python executable found in the Path environment is being executed. For example, I have MSYS2 installed with Python27 and since I've added C:\MSYS2 to the path before C:\Python36, the python.exe from the C:\MSYS2.... folder is being executed.

-1

I thought this answer might be helpful to others having multiple versions of python and wants to use pipenv to create virtual environment.

  1. navigate to the project directory, and run py -[python version] pip install pipenv, example: py -3.6 pip install pipenv
  2. run pipenv --python [version] to create the virtual environment in the version of the python you desire. example: pipenv --python 3.6
  3. run pipenv shell to activate your virtual environment.
-11

Just call the correct executable

albertov
  • 2,314
  • 20
  • 15
  • currently i am working on 2.5. simply elaborate me how can i run 2.6 also. in windows command prompt i had to write 'python' to enter python shell. and it is 2.5. in c drive i had both version installed. – Bilal Basharat Jan 03 '11 at 09:38
  • Instead of `python` to enter the shell try `python2.5` or `python2.6`. I'm not a windows user, but on unix /usr/bin/python is usually an alias to the fully qualified executable, I'm assuming python in windows is installed in a similar manner – albertov Jan 03 '11 at 10:28
  • 1
    On windows the executable name is always python.exe, but you change path to the executable. It's been explained several times already though. – jgritty Jan 03 '11 at 11:45