繁体   English   中英

使用 py2exe 时出现 FileNotFoundError

[英]FileNotFoundError when using py2exe

我有使用 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 - pysvn 在调用用 py2exe 编译的 exe 时出现 FileNotFoundError

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM