【问题标题】:Problem with PyInstaller and local packagesPyInstaller 和本地软件包的问题
【发布时间】:2022-02-14 04:55:21
【问题描述】:

我的项目结构如下:

  • example3/
    • window/
      • __init__.py
      • ...
    • __init__.py
    • __main__.py
  • setup.py
  • example.py

在主文件中:

import sys
from PySide2.QtWidgets import QApplication
import window

def main():
    app = QApplication(sys.argv)
    main_window = window.Main()
    main_window.show()
    app.exec_()

if __name__ == '__main__':
    main()

PyInstaller 的构建脚本 example.py:

from example3.__main__ import main

if __name__ == '__main__':
    main()

如何让 PyInstaller 识别我的项目的包或其中的模块? PyInstaller 只能看到使用 pip 安装的包。我读过一些关于钩子文件的东西,但并不真正了解如何去做。

我使用以下命令创建了可执行文件:

> pyinstaller example.py --onefile

当我尝试运行应用程序时,我收到错误消息:

> ./dist/example
Traceback (most recent call last):
  File "example.py", line 3, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module
  File "example3/__main__.py", line 7, in <module>
  File "/tmp/embedded.xpuoquuw.zip/shibokensupport/__feature__.py", line 146, in _import
ModuleNotFoundError: No module named 'window'
[127129] Failed to execute script 'example' due to unhandled exception!

【问题讨论】:

    标签: python module package pyinstaller hook


    【解决方案1】:

    可以通过告诉 PyInstaller 我的项目模块和包的搜索路径来解决问题:

    pyinstaller --onefile example.py --paths ./example3/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-23
      • 2011-03-14
      • 1970-01-01
      • 2019-04-27
      • 1970-01-01
      • 2022-01-17
      相关资源
      最近更新 更多