小编gir*_*ran的帖子

PyInstaller + UI文件 - FileNotFoundError:[Errno 2]没有这样的文件或目录:

我正在尝试使用PyInstaller将.py脚本导出到.exe,它依赖于使用Qt Designer创建的.ui文件.

我可以确认我的.py脚本在通过PyCharm运行时工作正常 - 我能够看到我用.ui文件创建的GUI.

但是,当我将.py脚本导出到.exe并启动它时,我在命令行中收到以下错误:

C:\Users\giranm>"C:\Users\giranm\PycharmProjects\PyQt Tutorial\dist\secSearch_demo.exe"
Traceback (most recent call last):
  File "secSearch_demo.py", line 13, in <module>
  File "site-packages\PyQt4\uic\__init__.py", line 208, in loadUiType
  File "site-packages\PyQt4\uic\Compiler\compiler.py", line 140, in compileUi
  File "site-packages\PyQt4\uic\uiparser.py", line 974, in parse
  File "xml\etree\ElementTree.py", line 1186, in parse
  File "xml\etree\ElementTree.py", line 587, in parse
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\giranm\\securitySearchForm.ui'
Failed to execute script secSearch_demo
Run Code Online (Sandbox Code Playgroud)

出于某种原因,.exe文件正在寻找路径中的.ui文件 - C:\ Users\giranm \

但是,已经做过一些研究,我被告知我需要使用os.getcwd()并确保我的脚本中有完整的路径.即使使用下面的代码,我仍然会尝试找到.ui文件时出错.

PyInstaller:IOError:[Errno 2]没有这样的文件或目录:

# import relevant modules etc...

cwd = os.getcwd()
securitySearchForm …
Run Code Online (Sandbox Code Playgroud)

python pyinstaller pyqt4 qt-designer

11
推荐指数
2
解决办法
7387
查看次数

标签 统计

pyinstaller ×1

pyqt4 ×1

python ×1

qt-designer ×1