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.
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
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
Maybe "Open with..." + 'Remember my choice' in context menu of explorer?
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.
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"
精彩评论