0

Questions similar to this one have been asked but I haven't seen a solution yet that helps me.

I am running Windows 7 and I've installed two versions of python, 3.3 and 2.7. Python 3.3 was the first version I installed and I was able to run scripts from the desktop (not the command line). I installed python 2.7 so that I could get numpy, scipy, and matplotlib down the road, but I found that all the scripts on my desktop defaulted to python 2.7. Since I coded in 3.3 this caused some issues.

I was able to fix this by right clicking the script icon, browsing programs, navigating to the python 3.3 file in my C: drive, and selecting the idle inside that directory. But then I found I wasn't able to run those scripts with python 2.7 using the exact same procedure.

Unfortunately I don't know command-line programming very much at all, and it seemed like most of the answers were geared towards that as a solution. Ideally I'd like to specify which python I want to run a script from the desktop, or possibly while I'm editing the script.

If it's relevant I'm running the eric python IDE, version 5.

I'd be happy to do the work of reading something fairly technical and long (like a blog post or PDF), but it won't help me much if it isn't aimed at beginners.

1

3 Answers 3

3

The Windows Python Launcher can automatically detect the Python from the shebang in your file.

Start your Python 3.3 scripts with

#!/usr/bin/env python3

and your Python 2.7 scripts with

#!/usr/bin/env python2.7

If you want to use the system's default Python version, you can just start the file with

#!/usr/bin/env python

This will also work on virtually all Unix systems.

Sign up to request clarification or add additional context in comments.

Comments

1

Maybe you should chose another IDE, like PyCharm, it could manage different versions of python easily (and gives tons of other useful features). Perhaps free PyDev could also make it.

Also, using virtualenv — is the best solution here, but it's a "hard way".

Comments

1

The method I use is to have several cmd.exe shortcuts on my desktop, each pointing at a different runpython.bat file, one for each version of python. Here is one command example from a shortcut:

%comspec% /k "C:\QA\Python\QAPYTH3\runpython.bat"

Here is a typical runpython.bat:

@SET PATH=%PATH%;"C:\Python32"
@SET PYTHONPATH=C:\Python32\Lib

@ASSOC .py=Python.File
@ASSOC .pyc=Python.CompiledFile
@ASSOC .pyo=Python.CompiledFile
@ASSOC .pyw=Python.NoConFile

@FTYPE Python.CompiledFile="C:\Python32\python.exe" "%%1" %%*
@FTYPE Python.File="C:\Python32\python.exe" "%%1" %%*
@FTYPE Python.NoConFile="C:\Python32\pythonw.exe" "%%1" %%*
@SET PATHEXT=.py;%PATHEXT%

Of course you don't have to call your .bat files the same as I have. Just adjust to suite your setup.

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.