Distributing python code with virtualenv?

malangi picture malangi · Apr 4, 2011 · Viewed 12.6k times · Source

I want to distribute some python code, with a few external dependencies, to machines with only core python installed (and users that unfamiliar with easy_install etc.).

I was wondering if perhaps virtualenv can be used for this purpose? I should be able to write some bash scripts that trigger the virtualenv (with the suitable packages) and then run my code.. but this seems somewhat messy, and I'm wondering if I'm re-inventing the wheel?

Are there any simple solutions to distributing python code with dependencies, that ideally doesn't require sudo on client machines?

Answer

Vinay Sajip picture Vinay Sajip · Apr 4, 2011

You can use a tool like PyInstaller for this purpose. Your application will appear as a single executable on all platforms, and include dependencies. The user doesn't even need Python installed!

See as an example my logview package, which has dependencies on PyQt4 and ZeroMQ and includes distributions for Linux, Mac OSX and Windows all created using PyInstaller.