Aidan
Aidan

Reputation: 99

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.

Upvotes: 4

Views: 9802

Answers (4)

Vicky Malhotra
Vicky Malhotra

Reputation: 360

You Can Configure The Python2 & python3 In Windows PC Like This:

  1. First Of All Install Python 2 & Python 3 in windows PC in C directory like this: C:\Python27 --> For Python2 C:\Python39 --> For Python3 Example:

After Installing Both Packages Go To Their Respective Folders And Copy python.exe & Paste In The Same Directory and rename the python - Copy with python2(In python27 folder) & python3(In python39 folder)

Python2: Python2

Python3: Python3

And Then Set Environment Vairable Like This:

All Done Now You Can Run Any Script Which May Compatible With Python2 or Python3 :)

Upvotes: 1

Bakfunk
Bakfunk

Reputation: 1

I would suggest to use virtual environment. Soon or later you would you might get dependency problems.

Upvotes: 0

Christopher Peisert
Christopher Peisert

Reputation: 24114

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.

Upvotes: 8

Dev Khadka
Dev Khadka

Reputation: 5451

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

Upvotes: 1

Related Questions