Change python version windows

Windows Command Line Python Change Version

New to Python and programming in general. I want to «install» a module from the command line for v 2.6, but it looks like my default Python is 2.5. (python —version returns 2.5.4)

How can I run my python setup.py build/install on 2.6 instead?

Many thanks in advance,

6 Answers 6

It depends on your operating system. If you have python 2.6 installed, you need to change your environment path to point to the 2.6 executable rather than the 2.5 executable. Do a Google search for changing your PATH variable on your operating system.

You can use explicit paths:

Recent versions of Python install PyLauncher. It is installed in the path so no need to add an explicit Python to the path, and it allows easy switching between multiple Python versions.

The default version can be specified in the environment variable PY_PYTHON , e.g. PY_PYTHON=3 (latest Python 3).

If you’re on Windows and you just need to run a different version of Python temporarily or, as was the case for me, a third party program needs to run a different version of Python, then modify your path at the command prompt:

This allowed the third party program to install successfully. The PATH modification only affects programs running in the same command prompt session and only lasts as long as the command prompt session..

They are a couple of ways you can do this 1) python virtual environment 2) pylauncher 3) Changing your windows path variable, tedious to say the least

It sounds like you are on windows. If so, run this with the python you want, to set that python as the windows one. (not my code)

How to change python version in command prompt if I have 2 python version installed

I have installed Anaconda 2 & 3 in my system. Anaconda 2 contains python 2.7 & Anaconda 3 contains python 3.6 .

I need to run my python code using command prompt & I need to use python 3.6 While I’m running python —version , I’m getting python 2.7.14 . How do I change it to python 3.6?

6 Answers 6


As you can see, I have both Python2 and Python3 installed.


I hope you know that the path of the python executable has to be added to the PATH environment variable in Windows. As you can see, the path of Python2 is placed above the path of Python3 in my system.

How does the cmd run commands?
It searches for an executable with the same name in the directory the cmd has been opened in, then goes and searches for the command in the locations provided in the Windows PATH variable, from TOP to BOTTOM. Which means, it gets the path to Python2 before it can get to the path of Python3. Therefore, every time you type python in your cmd, it runs Python2.
Both Python2 and Python3 executables have the same name in Windows so it never runs python3.

Читайте также:  Ftp server with windows server 2012

What seems like an obvious solution?
You might think, changing the name of python.exe to python3.exe for the Python3 executable will solve your problem. You are partially right, it will work. But you have to use python3 file.py or python3 —version , which I think, is understandable. But, pip will no longer work if you change the name of the original python executable. You will no longer be able to install external packages and modules.

How can this problem be solved?
You can create an alias for the Python3 executable called python3.bat .
.exe and .bat files can be called from the cmd directly without using their extension. We always write python filename.py instead of python.exe filename.py although both are correct. The same can be done with .bat files.
Go back to the first image and notice the python3.bat file below python.exe . That is my way of calling python3 without renaming my original python executable.

python3.bat
Create a new file using notepad or something and paste this %

dp0python %*
I don’t fully understand how this works except that dp0 basically runs python from inside the same directory and %* passes all the arguments to the python executable. Place this file inside your Python3 installation directory and your problem will hopefully be solved.


python3 basically runs your python3.bat file, which in turn runs the python.exe from its folder and passes the arguments to it.

Change default python version for command prompt

On my machine I have python3.4 and a recently downloaded python3.6 installed, I would like to set python3.6 as my default python used in command prompt.

I have removed the python34 path variable but my when I access python through the command prompt it still defaults to opening python3.4. I saw this question about access the non default python but that was for specific files.

Since posting the question:

I have also removed python34 from the system path variables.

Typing where python in command prompt returns this:

Typing echo %PATH% returns

The accepted answer on the proposed duplicate states it is possible but you shouldn’t do it, and doesn’t give details on how to do it.

4 Answers 4

You can run multiple python versions on your machine.

To make Python 3.6 default, just put path of Python 3.6 before path of Python 3.4 in system variables.

Читайте также:  Установка windows зависает при установке устройств

In python34 directory on C drive rename python.exe to python3.4.exe. After doing this if you run command python in command prompt it will open python 3.6. And to run python 3.4 you need to run command python3.4 as we have renamed it to python3.4.exe in python34 directory.

After making changes in system variables in environment variables you just need to restart your command prompt. No need to restart machine.

After some communication I guess I know what is the problem. Have you checked your system wide environment variables? Here is a link about how to:

  1. In Search, search for and then select: System (Control Panel)
  2. Click the Advanced system settings link.
  3. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  4. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

Further, your application(your command prompt) wide environment variables are appended after system wide ones.

How Should I Set Default Python Version In Windows?

I installed Python 2.6 and Python 3.1 on Windows 7 and set environment variable: path = d:\python2.6 .

When I run python in cmd , it displays the python version 2.6, which is what I want!
But, when I wrote a script in a bat file and ran it, the displayed python version was 3.1.

What’s going on here?

14 Answers 14

This is if you have both the versions installed.

Go to This PC -> Right-click -> Click on Properties -> Advanced System Settings.

You will see the System Properties . From here navigate to the «Advanced» Tab -> Click on Environment Variables .

You will see a top half for the user variables and the bottom half for System variables .

Check the System Variables and double-click on the Path (to edit the Path).

Check for the path of Python(which you wish to run i.e. Python 2.x or 3.x) and move it to the top of the Path list.

Restart the Command Prompt, and now when you check the version of Python, it should correctly display the required version.

The Python installer installs Python Launcher for Windows. This program ( py.exe ) is associated with the Python file extensions and looks for a «shebang» comment to specify the python version to run. This allows many versions of Python to co-exist and allows Python scripts to explicitly specify which version to use, if desired. If it is not specified, the default is to use the latest Python version for the current architecture (x86 or x64). This default can be customized through a py.ini file or PY_PYTHON environment variable. See the docs for more details.

Newer versions of Python update the launcher. The latest version has a py -0 option to list the installed Pythons and indicate the current default.

Читайте также:  Linux get java home

Here’s how to check if the launcher is registered correctly from the console:

Above, .py files are associated with the Python.File type. The command line for Python.File is the Python Launcher, which is installed in the Windows directory since it is always in the PATH.

For the association to work, run scripts from the command line with script.py , not «python script.py», otherwise python will be run instead of py . If fact it’s best to remove Python directories from the PATH, so «python» won’t run anything and enforce using py .

py.exe can also be run with switches to force a Python version:

Additionally, add .py;.pyw;.pyc;.pyo to the PATHEXT environment variable and then the command line can just be script with no extension.

How to change the python version of already existing virtualenv? [duplicate]

I have created a virtual environment using python 3.6, then I’ve made a system upgrade and I’ve got python 3.7 installed system wide. Now I can’t execute python files in that virtual environment because it’s searching for python 3.6.

How can I upgrade the virtualenv python version to match the system wide version or how to downgrade the python version for that particular virtual environment?

I’m using manjaro.

1 Answer 1

EDIT 1

Did some testing and found another more «graceful» way to (at least) update the executable. Let’s assume the virtual env was initially created like so virtualenv -p /path/to/my/python2.7 .venv . The executable can be updated to a specific python version like so: virtualenv —clear -p /path/to/my/python3.6 .venv . Please validate the python symlink in .venv/bin/python is updated using ls -la .venv/bin/python . The old executable(s) will still be in ./venv/bin/ .

Note: You need to have the specific target version of python installed.

See this link which explains it well.

Virtualenvwrapper comes with some convenient commands for managing your virtualenvs.

To change your Python version:

Deactivate your current environment session.

If you have many packages or libraries installed, it would be a good idea to make a requirements.txt file. Remember to edit version as necessary.

Remove the virtualenv with the wrapper command: rmvirtualenv

  • This will remove the virtualenv, but leave your project files.

Make a new virtualenv with the Python version you want.

Example: mkvirtualenv -p python3 env-name

You can specify the Python version with the -p flag and version. If you have a requirements.txt file, you can specify that with -r requirements.txt

Now bind your new virtualenv to your project directory. You can specify the full paths, but it is easier to have your new virtualenv activated and be in your project directory. Then, run the command:

Please let me/us know if this answer was helpful to you!

Оцените статью