How to deploy Python to Windows users?
Asked Answered
R

4

25

I'm soon to launch a beta app and this have the option to create custom integration scripts on Python.

The app will target Mac OS X and Windows, and my problem is with Windows where Python normally is not present.

My actual aproach is silently run the Python 2.6 install. However I face the problem that is not activated by default and the path is not set when use the command line options. And I fear that if Python is installed before and I upgrade to a new version this could break something else...

So, I wonder how this can be done cleanly. Is it OK if I copy the whole Python 2.6 directory, and put it in a sub-directory of my app and install everything there? Or with virtualenv is posible run diferents versions of Python (if Python is already installed in the machine?).

I also play before embedding Python with a DLL, and found it easy but I lost the ability to debug, so I switch to command-line plug-ins.

I execute the plug-ins from command line and read the STDOUT and STDERR output. The app is made with Delphi/Lazarus. I install others modules like JSON and RPC clients, Win32com, ORM, etc. I create the installer with bitrock.

UPDATE: The end-users are small business owners, and the Python scripts are made by developers. I want to avoid any additional step in the deployment, so I want a fully integrated setup.

Resnick answered 29/10, 2009 at 20:28 Comment(5)
What's wrong with a line in your application's README that says: download and install Python 2.6? What's wrong with making a two-part MSI where you're MSI installs the Python MSI?Enyo
Because I want a smooth instalation experience ;). I already have the 2 part setup. The python msi is instaled but is not activated or changed the path. Also, i face the situation where other version of python is already installed.Resnick
Because the end-user are small comapnies. The python scripts are made by developers. Have another step to perform is a barrier in the deployment and I want to avoid it (is like the issue with .net & java)Resnick
If the scripts are by developers then shouldn't they not be scared of installing Python?Rozele
Consider renaming "How to deploy Python to" -> "How to deploy portable Python 2.7 to" and tag "python" -> "python 2.7". Possibly even Windows -> W7, since W10 released in 2015? With this name a pair of duplicates exist. Old answers here may mislead modern users.Morrell
L
15

Copy a Portable Python folder out of your installer, into the same folder as your Delphi/Lazarus app. Set all paths appropriately for that.

Litigious answered 29/10, 2009 at 23:16 Comment(3)
I finally do something like this, copyng the full python folder as a subfolder with all the modules preinstaled, then point path to itResnick
It is surprising how frequently the "simplest thing that could possibly work" turns out to be a viable strategy.Litigious
"Portable Python is not being developed anymore", says their website now. They give alternatives.Coyne
C
13

You might try using py2exe. It creates a .exe file with Python already included!

Circumflex answered 29/10, 2009 at 20:30 Comment(2)
This not work for me, because is a important part of the product the ability to create plugins in python. Think like if my app is apache and anybody can build their website in python or php.Resnick
I would recommend using Pyinstaller, which does a pretty neat job of creating that .exe file and aggregating all the dependencies (even the python interpreter) into a dist folder of your script. You can check it out here. Also, Pyinstaller supports py3.3+ whereas py2exe fails almost always as stated hereCoimbatore
L
4

Integrate the python interpreter into your Delphi app with P4D. These components actually work, and in both directions too (Delphi classes exposed to Python as binary extensions, and Python interpreter inside Delphi). I also saw a patch for Lazarus compatibility on the Google Code "issues" page, but it seems there might be some unresolved issues there.

Litigious answered 29/10, 2009 at 23:21 Comment(0)
M
1

I think there's no problem combining .EXE packaging with a tool like PyInstaller or py2exe and Python-written plugins. The created .EXE can easily detect where it's installed and the code inside can then simply import files from some pre-determined plugin directory. Don't forget that once you package a Python script into an executable, it also packages the Python interpreter inside, so there you have it - a full Python environment customized with your own code.

Messieurs answered 30/10, 2009 at 5:27 Comment(4)
Yep... except that the same tool will be available on osx & linux. So, the best, simpler way is ship .py files.Resnick
I don't understand the context of the comment, mamcx. You can surely use py2exe for all platforms, and the .py plugins need not change.Messieurs
According to the website of py2exe is only for windows... or I miss something?Resnick
mamcx, you're right. Then use pyinstaller.org (the first one I mentioned, accidentally, because this is what I use for my code)Messieurs

© 2022 - 2024 — McMap. All rights reserved.