-1

I have made an .exe file which depends on the module pytube and would like to run it on my friends pc's, who does not have python installed. However every so often pytube is updated and I would like my .exe that I have given to my friend to stay up to date.

After outputting an .exe with Pyinstaller, is it possible to update the dependencies of the .exe, with the created .exe?

I have created a script that will go and fetch the updated module files from Github and save them into a given directory every time the .exe is run. I would like to use this script to update the dependencies of my .exe after Pyinstaller has created it.

My first thought was I would find where the dependencies were stored in the output of Pyinstaller and get my program to over write it with the newly downloaded module files. However:

A) I do not know where to find these files in the Pyinstaller output

B) I expect these module related files will be in a different format after Pyinstaller has created the .exe ect. than when they are downloaded from Github.

Does anyone have any advice on how to proceed with overcoming this problem?

Thanks.

valcofadden
  • 103
  • 3
  • PyInstaller creates self-unpacked zip file with extension .exe. When you run .exe then it create temporary folder, unpack modules and code and run it. In documentation should be something about this folder. But when you close program then it delete this folder. So it is better to download module to folder where you keep .exe file and add this folder to `sys.path` before imports. Using `sys.argv[0]` and `os.path.abspath()`, `os.path.dirname()` probably you could get folder used by .exe. You would have to find in Google how to get path of executed script. – furas Aug 02 '19 at 15:09
  • PyInstaller keeps original modules in .zip - they are not in different format. Script still can use modules added later - they don't have to be reformated. They have to be in folder which is in `sys.path` or you have to `append()` this folder to `sys.path` before `import`. – furas Aug 02 '19 at 15:13
  • @furas Thank you so much for your comment. This has helped me see how to move forward with the issue I am having. If you'd like to give your comments as an answer I'd be happy to select it as the best answer. – valcofadden Aug 03 '19 at 16:43

1 Answers1

0

PyInstaller creates self-unpacked zip file with extension .exe. When you run .exe then it creates temporary folder _MEI_xxxxxx (where xxxxxx is a random number), unpacks modules and code and runs it. But when you close program then it deletes this folder. So it is better to download modules to folder where you keep .exe file and add this folder to sys.path before imports.

You can read more in How the One-File Program Works


Probably you could get folder used by .exe. using something like this in main script:

HOME = os.path.abspath(os.path.dirname(sys.argv[0]))

or using __file__

HOME = os.path.abspath(os.path.dirname(__file__))

PyInstaller keeps original modules in .zip - they are not in different format. Script still can use modules added later - they don't have to be reformated. They have to be in folder which is in sys.path or you have to append() this folder to sys.path before import.


EDIT: There is question Determining application path in a Python EXE generated by pyInstaller on Stackoverflow which explains how to find folder used by script.

furas
  • 134,197
  • 12
  • 106
  • 148