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

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.

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?


Answer: You can create a bash script that creates the virtual env and runs the python
scripts aswell.

    
    
    !#/bin/bash
    virtualenv .venv
    .venv/bin/pip install <python packages>
    .venv/bin/python script
    

