Packing multiple scripts in PyInstaller

I use PyInstaller to turn two scripts into one executable, one of which calls the other. The problem I am facing is that I cannot figure out how to link the two scripts and still allow them to refer to each other:

The code causing the problem is that one script, script1.py contains:

 subprocess.call(['gksudo','python script2.py']) 

This works fine when I run the scripts normally, but once they are packaged in PyInstaller, I don’t know how to make the call work.

+4
source share
1 answer

I do not think that pyinstaller can handle a similar kit on its own device, at least I was not able to configure it, if possible. I also have a pretty big application where some calls

subprocess.Popen ('python' ...)

. How I finally did this was:

  • Change your subprocess calls to another python, for example subprocess.call(['gksudo','./python script2.py']) . Create two separate analyzes: one for the entry point and one for the rest of the scripts, in your case:

    a1 - script analysis1.py a2 - script analysis2.py

  • Create exe only from entry point scripts:

     pyz = PYZ(a1.pure) exe = EXE(pyz, a1.scripts, exclude_binaries=1, name={name here}, debug=False, strip=False, upx=True, console=1 ) 
  • Collect all the scripts

      coll = COLLECT( exe, a1.binaries, a1.zipfiles, a1.datas, a2.binaries, a2.zipfiles, a2.datas, python_tree, *additional_trees, strip=False, upx=True, name={}) 
  • Copy python to your distribution at the location specified in all subprocess calls, with any additional requirements that pyinstaller did not find (I had several such as matplotlib, pylab, etc.)

  • Create a start script that first changes any necessary environment variables to point to your package, and then run the application. In my case, what was needed was from the calling directory:

      export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH export LD_RUN_PATH=`pwd`:$LD_RUN_PATH 

Now all this was necessary if I wanted the application to run on computers that did not have python installed, or if they were installed on python, make sure that the application still uses all the libraries from the distribution package, and not any local libraries If in your case python is already installed on the target computers, I do not think that something like this would be necessary, and 3 steps would be enough.

+1
source

Source: https://habr.com/ru/post/1391361/


All Articles