Evpok
Evpok

Reputation: 4485

Port a multi-version python application to Windows

I have written a program in Python 3 that relies on another program in Python 2.7 for some core tasks. It works seamlessly on gnunux since most distribution have already 2.7 installed, I just have to require Python 3, and it's all good.

But now I want to port the bundle to Windows, and I don't know how to manage this. I have the following issues

I have the source code for everything I use, and everything is under libre licenses, so I don't have issues with compiling to PE or porting 2.7 scripts to 3, but it would be a tedious work. The only solution I have found so far is to port everything to Python 3. Can you think of another one?

Upvotes: 1

Views: 208

Answers (2)

Steven
Steven

Reputation: 28686

  • The recent Python Launcher for Windows (see also PEP 397) could be used to simulate the shebang/version behaviour. However, if you want to do this, the different versions of python must be installed on the system of course (and the launcher as well, registered as the default application for .py files)
  • Tools like PyInstaller and py2exe can bundle dynamically imported modules, only not discover them all by itself: you'll have to specify them yourself. I think your problem with these tools will be that they do not make applications with different versions of Python at the same time.

So I guess you're left with either requiring installation of python 2.7 and python 3 on the target system, or making separate exe's for your 2.7 and 3 scripts, and changing your subprocess calls to call these instead. (you could bundle the python installations with your own instead of using standard system-wide python installs, but you'd still have to change your subprocess calls instead of relying on windows default application for file extensions)

Upvotes: 1

Cata
Cata

Reputation: 498

How about using PyInstaller? Never used it myself but:

PyInstaller is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, and Mac OS X.

http://www.pyinstaller.org/

So you could convert both your programs to executables and then call one from inside the other.

Upvotes: 1

Related Questions