1

I have both python 2.7 and 3.2 installed on my system. I want some scripts to run using python 3.2, and some using 2.7 However, I don't want to go to IDLE every time to run scripts. Can anything be done such that the scripts execute themselves in the version specified?

I have tried some experimentation with sys and os modules, but that turned out to be useless.

1
  • Which operating system are you using? Commented Mar 28, 2014 at 13:05

1 Answer 1

6

If you are on *nix system then you can use Shebang

Example :

  • #!/usr/bin/env python3.2

Or

  • #!/usr/bin/env python2.7

Or You can run script using specific version

Example:

  • python2.7 yourscript.py

If you are on Windows System then you can use

  • #!/Python26/python
Sign up to request clarification or add additional context in comments.

2 Comments

To complete the answer if OP is running windows, you can do #!/Python26/python to run Python2.6 for instance.
IIRC, the Windows python runner tool (py.exe) can read the Unix shebangs just fine.

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.