3

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.

Christopher Peisert
  • 15,875
  • 3
  • 54
  • 78
Aidan
  • 79
  • 1
  • 2
  • 10
  • 1
    try `python3` - on Linux I have `python`, `python2`, `python2.7`, `python3`, `python3.6`, `python3.7`, and the same with `pip` - it is normal. So I can easily choose which one to use. – furas Aug 15 '19 at 01:56
  • @furas This returns 'python3.7 is not recognized...' – Aidan Aug 15 '19 at 01:58
  • do you have `python3` ? `python3.7`, etc. is natural on Linux. I assume you use Windows so you may have only `python` and `python3` and maybe `py`, `py3` or something similar. – furas Aug 15 '19 at 02:00
  • 1
    @furas I have python3.7, python2.7, and python3 – Aidan Aug 15 '19 at 02:01
  • Possible duplicate of [Adding directory to PATH Environment Variable in Windows](https://stackoverflow.com/questions/9546324/adding-directory-to-path-environment-variable-in-windows) – donkopotamus Aug 15 '19 at 02:02
  • Do you need all python instances to be available from the command line? Normally, if you install multiple Python into separate locations, they work together (or apart) just fine - what problem exactly are you looking for a solution to? (and yes, the path configuration is causing your situation, but I'm trying to find out what your resulting problem is) – Grismar Aug 15 '19 at 03:56

4 Answers4

4

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.

Christopher Peisert
  • 15,875
  • 3
  • 54
  • 78
  • 2
    Don't rename executables, but instead provide aliases, on Windows you can use batch files (or similar) like `python2.7.bat` and put them somewhere on the path to start the appropriate Python. Renaming will cause issues when updating or when other applications rely on `python.exe` being called `python.exe`. Adding all Python instances to the path also isn't needed. However, I would recommend using environment variables in your batch file to let each Python know where it is supposed to look for stuff. However, does OP even need all Python to work from the command line? – Grismar Aug 15 '19 at 03:54
  • @Grismar Fair point. See update regarding the Python Launcher for Windows. – Christopher Peisert Aug 15 '19 at 04:07
  • I'll leave the comment, but removed the down-vote, as you now do give the answer I think is closest to what OP should be considering (depending on their actual problem) – Grismar Aug 15 '19 at 04:17
1

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
Dev Khadka
  • 4,361
  • 3
  • 16
  • 31
0

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

Bakfunk
  • 1
  • 1
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – gehbiszumeis Aug 15 '19 at 08:21
0

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 :)

Vicky Malhotra
  • 320
  • 1
  • 3
  • 12