问题
I am using pdf2image in my code that in turn needs PATH to have the /bin
folder of the Poppler binaries. I will need this in the PATH even after I create an executable that can run on Windows. Pyinstaller is great but does not support poppler yet. How do I go about packaging this?
回答1:
Try pyinstaller --add-binary 'path\to\poppelr' script_name.py
The --add-binary
flag points pyinstaller
to the binary location so it can include it.
edit 2
Use the os
module to add to SYSTEM PATH
.
I am using Jitsi.exe
as a proof of concept. This is a program I have that is not on system path. replace it with the path to the program you want to run.
import os
# The os.eviron method returns a dict object of the users PATH
path = os.environ['PATH']
path = path + ';C:\Program Files\Jitsi' # Append the path to bin as a string
os.environ['PATH'] = path # Override value of 'PATH' key in the dict
print(os.environ['PATH']) # This is the new updated PATH
os.system('Jitsi') # Using system shell to call a program that was not on my PATH and now is
Note: This updates the path for the current process only. Once the python process ends the PATH is returned to it's previous state.
Tested on a windows system
来源:https://stackoverflow.com/questions/62049471/create-executable-for-windows-from-python-codebase-that-needs-poppler