FileNotFoundError when using py2exe

Question:

I have a gui program written in Python 3.9 that uses the PySide6 library. I want to make this into a .exe file using py2exe. However, when I try to open the executable I get the error:

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'

The executable file is generated by the commands in cmd:

C:Users...Documentsgui>py setup.py install

with setup.py being:

from distutils.core import setup
import py2exe, sys

sys.argv.append('py2exe')

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

The file im trying to convert is 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, however the solution seems incomplete. Python – FileNotFoundError for pysvn in calling exe compiled with py2exe

Asked By: Forum

||

Answers:

I am still not sure what causes the error nor how to fix it. The comments suggested that I use pyinstaller instead, which indeed fixes the problem.

Answered By: Forum
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.