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>Freeze options:</p>

<ul>
<li><a href="https://pypi.python.org/pypi/bbfreeze/1.1.3" rel="nofollow">https://pypi.python.org/pypi/bbfreeze/1.1.3</a></li>
<li><a href="http://cx-freeze.sourceforge.net/" rel="nofollow">http://cx-freeze.sourceforge.net/</a></li>
</ul>

<p>However, your target server should have the environment you want -> you should be able to 'create' it. If it doesn't, you should build your software to match the environment. </p>

<p>I found this handy guide on how to install custom version of python to a virtualenv, assuming you have ssh access: <a href="http://stackoverflow.com/a/5507373/5616110">http://stackoverflow.com/a/5507373/5616110</a></p>

<p>In virtualenv, you should be able to pip install anything and you shouldn't need to worry about sudo privileges. Of course, having those and access to package manager like apt makes everything a lot easier.</p>

python build