Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows: How to configure multiple versions of Python to work together?

I installed Python 2.7 a long time ago on my PC (I am running Windows 10). Today I decided to install Python 3.7, but after typing 'python' into the command prompt the console printed 'python 2.7...'

I have no idea as to what I should do. Would this be a problem with my path configuration? I considered uninstalling python 2.7 but I still want it installed on my computer.

like image 211
Aidan Avatar asked Oct 23 '25 14:10

Aidan


2 Answers

Configure multiple Python versions on Windows

Python 3.3 introduced the Python Launcher for Windows. Rather than using python.exe, call py and select the version with flags:

py -2.7
py -3

System-wide installations of Python 3.3 and later will put the launcher on your PATH.

Note on Virtual Environments (new in Python 3.5)

If the launcher is run with no explicit Python version specification, and a virtual environment (created with the standard library venv module or the external virtualenv tool) active, the launcher will run the virtual environment’s interpreter rather than the global one. To run the global interpreter, either deactivate the virtual environment, or explicitly specify the global Python version.

Outdated Method (not recommended)

  1. Rename executables - After installing multiple versions, change the names of the executables. For example, for Python 2.7, under the installation folder, rename python.exe to python27.exe and rename Python 3.7 from python.exe to python37.exe. Then on the command line, select the version by entering python27 or python37. Whichever version is preferred, could be left as just python.
  2. Add Path Environment Variables - For example, on Windows 10, go to the Windows menu and search for "environment variables" and click edit the system environment variables. In the System Properties dialog, click Environment Variables.... Under "System variables", select "Path". Click Edit.... Click New and add the first entry below. Click New again for each Path variable entry.
    • C:\Python27
    • C:\Python27\Scripts
    • C:\Python37
    • C:\Python37\Scripts

This will enable Python and pip. Be sure that paths match your actual installation directories.

like image 114
Christopher Peisert Avatar answered Oct 25 '25 05:10

Christopher Peisert


I would suggest using pyenv

I have been using it and is working well for me. Some of the handy features of pyenv are

  • It allows installing multiple version on python easily
  • It allows switching python version with one command in global, shell or folder level
  • It also allows creating virtual env using virtualevn extension
like image 35
Dev Khadka Avatar answered Oct 25 '25 05:10

Dev Khadka