auto installing dependencies with pip to run a python zip application ?

Irmen de Jong irmen at NOSPAM.xs4all.nl
Tue Sep 26 14:47:54 EDT 2017


Hi,
I've been using Python's executable zip application feature to neatly
package my little game into a single "executable" file.
Here "executable" means the user can simply start it by doubleclicking
it, or launching it from a shell prompt. Of course the user already has
to have a proper Python installation on their system but that's okay for me.

However, I would like to also take care of the library dependencies of
my game. Currently it requires pillow and sounddevice. If the user
doesn't have these installed, the game exits with an error message
telling the user to install these dependencies manually. I was thinking
about a way to automate this so that you don't have to install anything
manually to run the game.

I was thinking about the following solution:
- assume bare default Python (3.5+) installation
- use venv.EnvBuilder() to create a new virtualenv somewhere in the
user's home directory (~./virtualenvs/mygreatgame ?)
- use the with_pip=True argument so we also get pip installed into it
- exec() the python executable from the new virtual env and let that
"pip install -r mygamerequirements.txt"
- inject "./mygame.pyz" in sys.modules[0]
- run the game's main class and play!

Notice that I'm not looking for a fully standalone executable created by
things as cx_freeze, just something that is usable from within my zipped
application.

Any thoughts on this? Is it a good idea or something horrible? Has
someone attempted something like this before perhaps?

Irmen



More information about the Python-list mailing list