【发布时间】:2020-09-14 20:51:50
【问题描述】:
我在我的代码中使用了pdf2image,而这又需要PATH 来拥有Poppler 二进制文件的/bin 文件夹。即使在我创建了可以在 Windows 上运行的可执行文件之后,我也需要在 PATH 中使用它。 Pyinstaller 很棒,但 does not support poppler 还没有。我该如何包装这个?
【问题讨论】:
标签: python pyinstaller poppler
我在我的代码中使用了pdf2image,而这又需要PATH 来拥有Poppler 二进制文件的/bin 文件夹。即使在我创建了可以在 Windows 上运行的可执行文件之后,我也需要在 PATH 中使用它。 Pyinstaller 很棒,但 does not support poppler 还没有。我该如何包装这个?
【问题讨论】:
标签: python pyinstaller poppler
试试pyinstaller --add-binary 'path\to\poppelr' script_name.py
--add-binary 标志将pyinstaller 指向二进制位置,因此它可以包含它。
编辑 2
使用os 模块添加到SYSTEM PATH。
我使用Jitsi.exe 作为概念证明。这是我没有在系统路径上的程序。将其替换为您要运行的程序的路径。
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
注意: 这仅更新当前进程的路径。一旦 python 进程结束,PATH 就会返回到之前的状态。
在windows系统上测试
【讨论】:
--add-binary会更新系统PATH吗?