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.

CppLearner
  • 16,273
  • 32
  • 108
  • 163
  • 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. – Steven T. Snyder Mar 02 '12 at 20:21
  • @Series8217 Thank you. I think I can do that, but the main point is without installer; if it can be portable, nice! – CppLearner Mar 02 '12 at 20:23

2 Answers2

9

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.

Steven T. Snyder
  • 5,847
  • 4
  • 27
  • 58
  • 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. – CppLearner Mar 02 '12 at 20:19
  • @CppLearner 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. – Steven T. Snyder Mar 02 '12 at 20:27
  • 1
    @CppLearner 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. – Steven T. Snyder Mar 02 '12 at 20:28
3

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

Perica Zivkovic
  • 2,610
  • 24
  • 32