簡體   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