rwallace
rwallace

Reputation: 33375

Python programs coexisting on Windows

I'm looking for a way to let multiple Python programs coexist on the same Windows machine.

Here's the problem: suppose program A needs Python 2.5, B needs 2.6, C needs 3, and each of them needs its own version of Qt, Wx or whatever other modules or whatever.

Trying to install all these dependencies on the same machine will break things, e.g. you can install different versions of Python side-by-side but only one of them can have the .py file association, so if you give that to Python 2.5 then B and C won't work, etc.

The ideal state of affairs would be if program A could live in C:\A along with its own Python interpreter, Qt/Wx/MySQL driver/whatever and never touch anything outside that directory, ditto for B and C.

Is there any way to accomplish this, other than going the full virtual box route?

edit: I tried the batch file solution, but it doesn't work. That is, it works on simple test scripts but e.g. OpenRPG fails at some point in its loading process if its required version of Python doesn't own the file association.

Upvotes: 3

Views: 536

Answers (6)

hughdbrown
hughdbrown

Reputation: 49003

VirtualEnv.

virtualenv is a tool to create isolated Python environments.

The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.4/site-packages (or whatever your platform's standard location is), it's easy to end up in a situation where you unintentionally upgrade an application that shouldn't be upgraded.

See previous answer here.

The other tool you should look at is pip which is great for installing particular versions of a library into a virtual environment. If you need to run v 1.0 of a library in python v 2.x for one application and 1.1 of the same library in python v 2.x, for example, you will need virtualenv plus a means of installing a particular version in that environment. Virtualenv + pip is your best choice.

Upvotes: 7

rwallace
rwallace

Reputation: 33375

It looks like the best solution is a batch file that sets the file association before running the appropriate version of Python, as mentioned in the comments to one of the answers here: how to run both python 2.6 and 3.0 on the same windows XP box?

Upvotes: 0

inspectorG4dget
inspectorG4dget

Reputation: 113915

Have you considered compiling them to EXEs? Once you do that, all you have to do is call the EXE, for which the machine does not require python to be installed. All the required modules etc are packaged with the distribution when you compile.

Upvotes: 1

Bryan Oakley
Bryan Oakley

Reputation: 385910

write a python script that mimics the way unix shells handle scirpts -- look at the first line and see if it matches #!(name-of-shell). Then have your python script exec that interpreter and feed it the rest of its arguments.

Then, associate .py with your script.

Upvotes: 0

Krzysztof Bujniewicz
Krzysztof Bujniewicz

Reputation: 2417

Use batch files to run scripts, write in notepad for example:

c:\python26\python.exe C:\Script_B\B.py

and save it as runB.bat (or anything .bat). It will run with interpreter in c:\python26\python.exe file specified after a whitespace.

Upvotes: 2

jldupont
jldupont

Reputation: 96716

One solution would be to craft a batch file that invokes the correct interpreter for a given application. THis way, you can install additional interpreters in separate folders.

Probably not perfect but it works.

Upvotes: 1

Related Questions