0

When I open CMD (on windows 10) and enter python it initializes python 3.6.0

C:\>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Now I recently also installed 2.7.6 the interpreter. How can I call both version of Python from CMD?

desired outcome

C:\>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> ^Z
C:\>python2.6
Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
1
  • 1
    You can copy or symlink python.exe to python2.7.exe, and then add the Python 2.7 installation directory to the PATH environment variable. Or just use the py.exe launcher, e.g. py -2 or py -2.7. Commented Jun 17, 2017 at 12:17

2 Answers 2

2

You can use Python launcher for Windows:

  • Python 2.7 interptreter:

    C:\> py -2.7

  • Python 3.6 interpreter:

    C:\> py -3.6

You also can run a script with a specific interpreter:

C:\> py -2.7 myScript.py

Sign up to request clarification or add additional context in comments.

Comments

0

If its windows machine, to open a specific version of python you can use py from the command line.

example: py2.7 #for version 2.7

and

py3.6 #for version 3.6

if its a Linux machine you can use the following commands in the command line python

python2.7 #opens version 2.7

and

python3.6 #opens version 3.6

1 Comment

It's py -2.7 and py -3.6. py on its own used to default to the latest version of Python 2 installed. Starting with 3.6, it uses the latest version of Python 3. An active virtual environment overrides this default. You can also override it via the PY_PYTHON environment variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.