【问题标题】:FileNotFoundError when using py2exe使用 py2exe 时出现 FileNotFoundError
【发布时间】:2023-01-13 09:08:00
【问题描述】:

我有使用 PySide6 库的 Python 3.9 编写的 gui 程序。我想使用 py2exe 将它变成一个 .exe 文件。但是,当我尝试打开可执行文件时出现错误:

Traceback (most recent call last):
  File "main.py", line 3, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "zipextimporter.pyc", line 167, in exec_module
  File "PySide6\__init__.pyc", line 123, in <module>
  File "PySide6\__init__.pyc", line 111, in _find_all_qt_modules
FileNotFoundError: [WinError 3] Path not found: 'C:\\Users\\...\\Documents\\gui\\dist\\library.zip\\PySide6'

可执行文件由cmd中的命令生成

C:\Users\...\Documents\gui>py setup.py install

setup.py 是

from distutils.core import setup
import py2exe, sys

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
    windows = [{'script': "main.py"}],
)

我试图转换的文件是 main.py

import sys

from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton


# Subclass QMainWindow to customize your application's main window
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("My App")

        button = QPushButton("Press Me!")

        # Set the central widget of the Window.
        self.setCentralWidget(button)


app = QApplication(sys.argv)

window = MainWindow()
window.show()

app.exec()

Another post had a similar problem with the pysvn library,但是解决方案似乎不完整。 Python - FileNotFoundError for pysvn in calling exe compiled with py2exe

【问题讨论】:

  • 使用 pyinstaller
  • 是的,这样效果更好。谢谢! @亚历山大

标签: python pyside py2exe


【解决方案1】:

我仍然不确定是什么原因导致错误,也不确定如何修复它。 cmets 建议我改用 pyinstaller,这确实解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-12
    • 1970-01-01
    • 2014-07-09
    • 1970-01-01
    相关资源
    最近更新 更多