简体   繁体   English

pyinstaller.exe 文件在导入另一个模块后不起作用

[英]pyinstaller .exe file does not work after import another module

I created an exe file with pyinstaller from a python file, which is shown bellow and the file worked correctly.我使用 pyinstaller 从 python 文件创建了一个 exe 文件,如下所示,文件工作正常。 but when i import a module like vtk or something else the generated exe file does not worked.但是当我导入像 vtk 或其他东西的模块时,生成的 exe 文件不起作用。 How can i fix this issue?我该如何解决这个问题?

import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow
from simulation import SimulationWindow

class mainwindow(QMainWindow, SimulationWindow):
    def __init__(self, parent=None):
        super(mainwindow, self).__init__(parent)
        self.setupUi(self)
        self.show()
       
if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    demowindow = mainwindow()   
    demowindow.show()
    sys.exit(app.exec_())

there is a complicated way by using hooks, pyinstaller does not capture all the modules, unfortunately.使用钩子有一种复杂的方法,不幸的是,pyinstaller 不会捕获所有模块。 so you need to use hooks for that.所以你需要为此使用钩子。

easy way is just copy the module folder from site-packages and paste is beside your executable, problem solved简单的方法就是从 site-packages 复制模块文件夹并粘贴到你的可执行文件旁边,问题就解决了

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

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