3

My program has been written on python 3.1 (it was the biggest mistake I've ever made). Now I want to use a few modules that were written on 2.6.

I know that it's possible to specify the interpreter in Unix #!/usr/bin/python2.6. But what if I use Windows? Does any way to specify the interpreter exist in Windows?

Edit: I want to be able to use both interpreters simultaneously.

4
  • 3
    "it was the biggest mistake I've ever made"... you must have a very simple life ;) Commented Jul 13, 2010 at 12:15
  • Do you want to run only a particular script with 2.6 or all .py scripts? Commented Jul 13, 2010 at 12:46
  • It's not a mistake, just, er, overly forward-thinking! Commented Jul 13, 2010 at 12:49
  • I only want to run particular scripts with 2.6. Commented Jul 13, 2010 at 13:08

5 Answers 5

6

the shebang line:

#!/usr/bin/python2.6

... will be ignored in Windows.

In Windows, you must call the correct python interpreter directly (AFAIK). Normally, people add their Python version specific directory (c:\Python26) to their PATH (environment variable) so you can just type "python" at any command line and it will invoke the interpreter.

However, you can also call any specific interpreter you want.

for example, on Windows I have both Python 2.6 and 3.1 installed (residing in c:\Python26 and c:\Python31 respectively). I can run a script with each one like this:

c:\python26\python foo.py

or

c:\python31\python foo.py
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to mix in the same runtime both 2.6 and 3.1 you may be interested in execnet. Never tested directly, however

  • Edit: looking at you comments on another answer, I understood better the question

1 Comment

Exectly, I want to use both interpreter simultaneously. It looks like execnet does what I need. Thanks for the pointing.
0

Maybe "Open with..." + 'Remember my choice' in context menu of explorer?

3 Comments

This will change the setting for all the .py files, even those written in 3.1
I want to call modules from 3.1 program
What lacopo was trying to point out was that even non 3.1 scripts will be interpretted with 3.1.
0

If you want to go back from Python 3 to Python 2 you could try 3to2 to convert your code back to Python 2. You can't easily mix Python 2 and 3 in the same program.

Comments

0

If you go into Control Panel -> System -> Advanced -> Environment Variables, and then add Python 2.6 to the PATH variable (it's probably located at C:\Python26 or C:\Program Files\Python26) -- and make sure Python 3.1 isn't in it -- then if you type python at the command prompt, you'll get 2.6 instead. As for Explorer, you'll want to associate it by using the Open With... dialog. Browse to the path (probably C:\Python26\python.exe) and set it. Make sure you check to make it the default before you hit OK.

To add the to PATH variable, you'll have to add a ; on the end of the current PATH variable and then add the folder's path after it (remove 3.1 if needed). For example: PATH="C:\Program Files\Emacs23\bin;C:\Cygwin\bin;C:\Python31" would become: PATH="C:\Program Files\Emacs23\bin;C:\Cygwin\bin;C:\Python26"

Comments

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.