How can I make portable python desktop application?
Asked Answered
V

2

17

The requirement is to make an application portable, meaning no installer. I looked at py2exe and I am afraid I need to run install if I want to run it under Windows.

So my question is, can I make a portable python desktop application without any installation (all dependencies and libs are packaged), dragging from USB / CD will run it?

(This is critical because it's a headache for users to install C++ Run Time library...)

Thanks.

Valenza answered 2/3, 2012 at 19:57 Comment(2)
You say it's a headache for users to install the C++ runtime library... why not include it in your program's installer? I have packaged Python software with py2exe using Inno Setup for installation. I just have the installer run the Visual C++ runtime redistributable with the /qb flags so the user doesn't have to do anything.Poach
@Series8217 Thank you. I think I can do that, but the main point is without installer; if it can be portable, nice!Valenza
P
10

You can use this method with py2exe: http://www.py2exe.org/index.cgi/SingleFileExecutable

Basically, you use NSIS to package all of the required files and folders into a single executable. When you run it, the required files are expanded to a temporary directory, the executable is run, and when it exits, the temporary files are deleted automatically.

There is also an example that comes with py2exe which uses Inno Setup instead of NSIS to achieve the same result. It's installed to site-packages\py2exe\samples\extending.

Poach answered 2/3, 2012 at 20:14 Comment(3)
Thank you. I read it, please correct if I am wrong: so after I compile the installer, I can copy the whole folder to another computer. Run the executable, it will generate appropriate files like dlls in a tmp folder, which will be deleted once the user close the app. My application requires persistence because we have an XML database, so we don';t want to destroy the records. How do I know what are created in the tmp? Thanks.Valenza
@Valenza Correct. After you compile the "installer", the only executable you need to move to the other computer is the "installer". When you run that executable, it unpacks its contents (the application exe and required DLL files, etc), runs the application, and when the application exits it deletes the temp folder. You can control the behavior by editing the example NSIS script.Poach
@Valenza If you want persistent data, store it where its supposed to go... perhaps %homepath%\AppData\MyXMLDB or something similar. Then the application can always find it, regardless of where you execute it from.Poach
V
4

You can also fork Portable Python and modify to include your application and libraries you need. It runs from any drive/network location without installation and you can pick do you want 2.x.x or 3.x.x based Python core

Vent answered 19/9, 2013 at 7:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.