Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyInstaller和PySide,如何包含imageformats文件夹?_Python_Qt_Pyside_Pyinstaller - Fatal编程技术网

Python PyInstaller和PySide,如何包含imageformats文件夹?

Python PyInstaller和PySide,如何包含imageformats文件夹?,python,qt,pyside,pyinstaller,Python,Qt,Pyside,Pyinstaller,我为一小时内问两个问题感到难过,但哦,好吧 我正在使用Python和PySide构建一个相当复杂的应用程序。终于发布的日子快到了,所以我想把这个应用程序构建成一个exe。我正在使用PyInstaller构建我的exe二进制文件 此应用程序的一部分加载一些JPEG图像。我在将这些图像加载到我的应用程序时遇到问题(它们就是不显示),所以我不得不这样做: path = os.getcwd() app.addLibraryPath(path) #app being QApplication() 这使它

我为一小时内问两个问题感到难过,但哦,好吧

我正在使用Python和PySide构建一个相当复杂的应用程序。终于发布的日子快到了,所以我想把这个应用程序构建成一个exe。我正在使用PyInstaller构建我的exe二进制文件

此应用程序的一部分加载一些JPEG图像。我在将这些图像加载到我的应用程序时遇到问题(它们就是不显示),所以我不得不这样做:

path = os.getcwd()
app.addLibraryPath(path) #app being QApplication()
这使它工作正常(此路径包含
imageformats
文件夹,其中包含
qjpeg4.dll
和其他图像加载插件)

然而,现在我在用PyInstaller打包它时遇到了同样的问题。我必须使用
--onefile
标志,但即使我没有使用,我也可以看到PyInstaller没有包含
imageformats
文件夹—找不到

我知道这是个问题,因为当我手动将imageformats文件夹复制/粘贴到exe所在的文件夹中时,应用程序按预期工作


有没有办法强制PyInstaller包含我指定的文件夹,特别是这个imageformats文件夹?

使用PyInstaller时有一个选项,
--additional hooks dir=HOOKSDIR
,它会将附加目录附加到PyInstaller的搜索路径。

PyInstaller的选项
--add data


Qt资源文件中有JPEG吗?查找qjpeg4.dll或加载图像本身有问题吗?PyInstaller用户手册中说--“附加hooks dir=HOOKSPATH搜索钩子的附加路径。这将进入扩展钩子路径,请参阅下面的分析。”因此我认为这个答案不正确。您还需要编写一个自定义挂钩模块。修改spec文件使其包含dll不是同样容易吗?
pyinstaller --add-data "\path\of\imageformats;imageformats" target.py