python-3.xpippyinstallerexecutableauto-update

Correct way to manage python modules after packed into binary executable using pyinstaller


How I met the problem

I'm currently working on a way of patching/updating software remotely, without asking the users to reinstall whenever I publish an newer version

(that is, no need to repack executable for me, no need to reinstall executable for the user)

What I currently have

Currently I use a dummy script (compiled into binary using pyinstaller) to import the actual script (compiled into .pyd), and check for updates on-boot. (see this reply for detailed description)

However, this solves only frontend statics and backend logic parts of patching/updating, since I have to include all necessary modules while building the executable using pyinstaller, which limits what modules I'm able to use in the future updates, whenever I need a new module, I still have to recompile to pack it in, and ask the users to reinstall.

What is the problem

So I came up with another idea, that is, keep the needed module-list (requirements.txt) on the server along with the other static files, while checking for updates on-boot, also check if all modules are installed in the contents_directory.

To achieve this, I need to access pip in the compiled binary, along with the --target argument to locate the target directory to contents_directory (see this).

What I've found to try to solve it

I've found this, using subprocess to invoke python -m pip install, but subprocess achieve this by running the python command, which the users might not have it installed nor setup python PATH.

There's also another way of straight import pip in the python code (see this for code example), but this method seems to be officially unrecommended, since most part of pip's main program is in pip._internal.

Conclusion of the problem

What's the correct way to manage python modules (including install&uninstall modules), after it's been packed into binary executable using pyinstaller, and send to users who most likely don't have python installed.

Other information


Solution

  • I don't think you need to access pip.

    If the user approves the upgrade. You can directly download a zip file which includes all the necessary mdules and then unzip it to the exe installation path. You may also fetch the data from the server which tells you the modules to be deleted.

    At last, show a messagebox and tell the user to relaunch the software.

    This is what I currently do. Hope it helps.