How to call a specific version of Python WITHIN in script.py - Windows

What line of text should I put at the top of script.py to invoke the specific version of Python that I need to use?

I have two versions of Python for Windows XP, 2.6.5 and 2.7.2. Each of them has its own special modules and has been installed by separate applications. My scripts are placed on the desktop, so I can double-click and run them conveniently.

The problem is that all my scripts call 2.6.5, which is great for scripts that use modules installed with 2.6.5, but my scripts designed for 2.7.2 do not run. They call Python 2.6.5 without the modules I need to import.

I tried to print various headers with and without #! call 2.7.2 when I need it, but either my syntax is incorrect or it is simply impossible to specify under Windows. Can someone tell me the exact syntax of the string I need to add to my script. The python.exe file for 2.7.2 is stored in the folder C: \ OSGeo4W \ bin

Thanks for letting me know which line to put at the top of script.py in order to invoke the exact version of Python that I should use.

+7
source share
3 answers

If you installed Python 3.3 on your system, he added a new launcher for Python scripts, which means you can use the shebang line:

#!python2.7 print "Hello" 

or

 #!python3.3 print("World") 

will work and run the appropriate python, or you can specify the full path to the Python interpreter or create an ini file that defines the abbreviations for specific Python interpreters.

See PEP 397 for various options available on Windows shebang lines.

If you do not want to install Python 3.3, you can also install the launcher separately .

+9
source

Instead of putting the script on the desktop, place the shortcut on the desktop. This process is described in the techrepublic.com article. Specify the appropriate interpreter as the program to run and list one of your .py files as a parameter in the same field.

+1
source

There is no "shebang" notation on Windows.

You will need to change the file association for the .py files in order to use the 2.7.2 installation ("Open with", "Use default application").

0
source

All Articles