Create executable for Windows from python codebase that needs poppler

泄露秘密 提交于 2021-01-29 09:00:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!