howto invoke specific version of pyton within a script on Wx

A forum for general discussion of the Python programming language.

howto invoke specific version of pyton within a script on Wx

Postby markMDW » Thu Mar 07, 2013 5:51 pm

I have two versions of Python installed on Windows XP. 2.6.5 and 2.7.2. Because of certain modules in use with each, I need to invoke either one or the other within my python scripts. I have various scripts.py on my desktop that I run by double clicking. The scripts always run 2.6.5, which causes the 2.7.2 scripts to fail. I have some scripts for each. I want to invoke the particular version I need WITHIN the script itself.

What is the syntax (using #! shebang or something similar in Windows XP) to specify this. I've tried, for instance...
#! C:/OSGeo4W/bin/python2.7.2
#! C:/OSGeo4W/bin/python.exe
#! C:/OSGeo4W/bin/python
#! c:/OSGeo4W/bin/python
C:/OSGeo4W/bin/python.exe
c:/OSGeo4W/bin/python.exe
...and countless others you'd likely be glad I didn't past in here. (yes, the python.exe I want to implement is in this directory: C:/OSGeo4W/bin/python.exe)

Thanks :D
markMDW
 
Posts: 2
Joined: Thu Mar 07, 2013 5:27 pm

Re: howto invoke specific version of pyton within a script o

Postby setrofim » Thu Mar 07, 2013 7:01 pm

Windows doesn't use shebang to determine how to open/execute files. It uses the file extension instead. You can use the combination of assoc and ftype commands in cmd.exe to set up the extension associations for different versions of Python (e.g. .py6 for 2.6 and .py7 for 2.7), and then rename your scripts accordingly. Alternatively, you can just write batch file wrappers for you scripts that invoke the appropriate version of Python.
Last edited by setrofim on Thu Mar 07, 2013 7:03 pm, edited 1 time in total.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: howto invoke specific version of pyton within a script o

Postby ichabod801 » Thu Mar 07, 2013 7:03 pm

You need to have 3.3 installed to use the shebang line on Windows. That's the first version that includes the Python Launcher for Windows (see PEP 397).
Craig "Ichabod" O'Brien
Minimalist, buddhist, theist, and programmer
Current languages: Python, SAS, and C++
Previous serious languages: R, Java, VBA, Lisp, HyperTalk, BASIC
ichabod801
 
Posts: 84
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC

Re: howto invoke specific version of pyton within a script o

Postby markMDW » Mon Mar 11, 2013 1:23 pm

excellent! Thanks to both of you for the answers I need.
markMDW
 
Posts: 2
Joined: Thu Mar 07, 2013 5:27 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest