Is there a way to compile python application into static binary?
<p>What I'm trying to do is ship my code to a remote server, that may have different python version installed and/or may not have packages my app requires.</p>

<p>Right now to achieve such portability I have to build relocatable virtualenv with interpreter and code. That approach has some issues (for example, you have to manually copy a bunch of libraries into your virtualenv, since <code>--always-copy</code> doesn't work as expected) and generally slow.</p>

<p>There's (in theory) <a href="https://wiki.python.org/moin/BuildStatically">a way</a> to build python itself statically.</p>

<p>I wonder if I could pack interpreter with my code into one binary and run my application as module. Something like that: <code>./mypython -m myapp run</code> or <code>./mypython -m gunicorn -c ./gunicorn.conf myapp.wsgi:application</code>.</p>

<p>You might wish to investigate <a href="http://nuitka.net/" rel="nofollow">Nuitka</a>. It takes python source code and converts it in to C++ API calls. Then it compiles into an executable binary (ELF on Linux). It has been around for a few years now and supports a wide range of Python versions.</p>

<p>You will probably also get a performance improvement if you use it. Recommended.</p>

python build