Aayush Mahajan
Aayush Mahajan

Reputation: 4033

Specifying version of python to be used to run a script

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.

Upvotes: 1

Views: 102

Answers (1)

Rahul Patil
Rahul Patil

Reputation: 1034

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

Upvotes: 6

Related Questions