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.

Nope
  • 34,682
  • 42
  • 94
  • 119
mamcx
  • 15,916
  • 26
  • 101
  • 189
  • 1
    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? – S.Lott Oct 29 '09 at 20:49
  • 2
    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. – mamcx Oct 29 '09 at 20:58
  • 1
    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) – mamcx Oct 29 '09 at 21:16
  • 1
    If the scripts are by developers then shouldn't they not be scared of installing Python? – Nope Oct 30 '09 at 00:10
  • 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. – halt9k Mar 02 '23 at 16:56

4 Answers4

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.

Caleb Hattingh
  • 9,005
  • 2
  • 31
  • 44
  • I finally do something like this, copyng the full python folder as a subfolder with all the modules preinstaled, then point path to it – mamcx Oct 16 '13 at 20:59
  • 1
    It is surprising how frequently the "simplest thing that could possibly work" turns out to be a viable strategy. – Caleb Hattingh Oct 16 '13 at 22:57
  • 3
    "Portable Python is not being developed anymore", says their website now. They give alternatives. – Jim DeLaHunt May 10 '18 at 16:07
13

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

Jason Baker
  • 192,085
  • 135
  • 376
  • 510
  • 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. – mamcx Oct 29 '09 at 20:57
  • 3
    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](https://pyinstaller.readthedocs.io/en/stable/index.html). Also, Pyinstaller supports py3.3+ whereas py2exe fails almost always as stated [here](https://stackoverflow.com/questions/41578808/python-indexerror-tuple-index-out-of-range-when-using-py2exe) – Yashash Gaurav Oct 03 '18 at 11:46
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.

Caleb Hattingh
  • 9,005
  • 2
  • 31
  • 44
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.

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
  • Yep... except that the same tool will be available on osx & linux. So, the best, simpler way is ship .py files. – mamcx Oct 30 '09 at 20:39
  • 1
    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. – Eli Bendersky Oct 31 '09 at 06:38
  • According to the website of py2exe is only for windows... or I miss something? – mamcx Oct 31 '09 at 17:24
  • mamcx, you're right. Then use http://www.pyinstaller.org/ (the first one I mentioned, accidentally, because this is what I use for my code) – Eli Bendersky Nov 02 '09 at 03:47