0

I use python 3.3.2 on windows everyday, so i added C:\Python33 to my PATH in order to be able to call "python foo.py" from console and get python 3.3.2 to execute it.

But sometimes, i also need to use python 2.7. How could i add a "python27" entry to my path, in order to call "python27 bar.py" and get python 2.7 to execute it ?

0

2 Answers 2

2

Run it using pylauncher:

C:\> py -2.7 bar.py

Or add at the top of bar.py:

#! python2.7

then:

C:\> py bar.py

will use Python 2.7 version.

If pylauncher is configured to handle Python scripts; you could just call:

C:\> bar.py

Or

C:\> bar

if .py is in PATHEXT

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

Comments

0
  1. Move C:\Python27\python.exe to C:\Python27\python27.exe
  2. Add C:\Python27 to your PATH.

3 Comments

This trick does the job, but comes with new problems as other tools like "pip" now can't find C:\Python27\python.exe
If you're working in a virtualenv (highly recommended), you can specify the python version when you create the virtualenv like this: "virtualenv -p C:\python27\python27.exe myenv". Then, when the env is activated, pip and other tools will use the environment's python (which would be 2.7), in addition to the other benefits of virtualenv.
I haven't heard of virtualenv, i'll try it. Thanks for the tip !

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.