Virtualenv within single executable
<p>I currently have an executable file that is running Python code inside a zipfile following this: <a href="https://blogs.gnome.org/jamesh/2012/05/21/python-zip-files/" rel="nofollow">https://blogs.gnome.org/jamesh/2012/05/21/python-zip-files/</a></p>

<p>The nice thing about this is that I release a single file containing the app. The problems arise in the dependencies. I have attempted to install files using pip in custom locations and when I embed them in the zip I always have import issues or issues that end up depending on host packages. </p>

<p>I then started looking into virtual environments as a way to ensure package dependencies. However, it seems that the typical workflow on the target machine is to source the activation script and run the code within the virtualenv. What I would like to do is have a single file containing a Python script and all its dependencies and for the user to just execute the file. Is this possible given that the Python interpreter is actually packaged with the virtualenv? Is it possible to invoke the Python interpreter from within the zip file? What is the recommended approach for this from a Python point of view?</p>

<p>You can create a bash script that creates the virtual env and runs the python scripts aswell. </p>

<pre><code>!#/bin/bash
virtualenv .venv
.venv/bin/pip install &lt;python packages&gt;
.venv/bin/python script
</code></pre>

python linux virtualenv executable