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>To freeze your python executable and ship it along your code, embed it in an empty shell app. Follow the instructions how to embed python in an application from the <a href="https://docs.python.org/3/extending/embedding.html#embedding-python-in-another-application" rel="nofollow">official documentation</a>. You can start building a sample app directly from the C sample code they give on the web page. </p>

<p>Make that program execute your python application through the embedded python. Ship the program, the embedded python you used and your python program. Execute that program.</p>

python build