使用cx_Freeze、PyQt5、Python3构建的exe不能导入ExtensionLoader_PyQt5_QtWidgets。py和运行

时间:2022-10-25 18:02:19

I'm trying to pack my app Python3, PyQt5 for Windows using cx_Freeze. I've installed Python 3.4.3, Python-win32, PyQT5, cxfreeze. Application itself, run in console, works fine.

我正在尝试使用cx_Freeze为Windows打包我的应用Python3, PyQt5。我已经安装了Python 3.4.3, pythonwin32, PyQT5, cxfreeze。应用程序本身在控制台运行,运行良好。

I try to pack it with cx_freeze: python setup.py build_exe. It works on the same host. But when I move it to another clean installation WinXP it gives an error:

我尝试用cx_freeze: python设置来包装它。py build_exe。它在同一台主机上工作。但是当我将它移动到另一个干净的WinXP系统时,它会产生一个错误:

Traceback:
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27 in <module>
File "pyftp1.py" in 7, in <module>
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", in 2237, in _find_and_load
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", in 2226, in _find_and_load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", in 1191, in _load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", in 1161, in _load_backward_compatible
File "ExtensionLoader_PyQt5_QtWidgets.py", line 22, in <module>
File "ExtensionLoader_PyQt5_QtWidgets.py", line 14, in __bootstrap__ 
ImportError: DLL load failed: Не найден указанный модуль.

English: "specified module was not found".

“未找到指定的模块”。

Here's my setup.py:

这是我的setup . py:

import sys
from cx_Freeze import setup, Executable

includes = ['sys', 'PyQt5', 'PyQt5.Core', 'PyQt5.QtGui', 'PyQt5.QtWidgets', 'os', 'os.path', 'ftplib',
    'traceback', 'time',]
excludes = []
packages = ['os', 'PyQt5']
path = []
build_exe_options = {
   'includes': includes,
   'excludes': excludes,
   'packages': packages,
   'path'    : path,
   #'dll_includes': ['msvcr100.dll'],
   'include_msvcr' : True,
   'include_files': [
       (r'C:\Windows\System32\msvcr100.dll', 'msvcr100.dll'),
   ],

}


base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

setup(
    name = "pyftp1",
    version = "0.1",
    description = "Foto uploader",
    options = {'build_exe_options': build_exe_options},
    executables = [Executable("pyftp1.py", base=base, appendScriptToLibrary=False, copyDependentFiles=True)]
)

Also I found it doesn't copy msvcr100.dll file, however I've stated it twice! I've copied it manually to target host.

我还发现它没有复制msvcr100。dll文件,但是我已经说过两次了!我已经手工复制到目标主机。

Here's pyftp1.py:

pyftp1.py:

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys, time, os, hashlib
import ftplib
import traceback
from PyQt5.QtWidgets import QApplication, QWidget, QFileDialog  # <-- Line 7
from PyQt5.QtWidgets import QPushButton, QHBoxLayout, QVBoxLayout, QScrollArea, QLineEdit, QCheckBox
from PyQt5 import QtGui
from PyQt5.QtGui import QIcon, QPalette, QLinearGradient, QColor, QBrush
from PyQt5.QtCore import QObject, QThread, pyqtSignal, pyqtSlot

2 个解决方案

#1


3  

Solution.

After struggling during a lot of time with a problem I've found the solution. Many how-to do not take an account specific versions of software, or some specific modules used, or even they do not check .exe on fresh system, which has no your libraries dlls and so on. Here's working and tested solution.

在与一个问题纠缠了很长时间之后,我找到了解决办法。许多how-to都不考虑特定版本的软件,或使用的特定模块,甚至不检查新系统上的.exe,它没有库dll等。这是工作和测试的解决方案。

First, I removed cx_freeze and used py2exe. I've built all the stuff on WinXP 32-bit - for the goal it could be run on nearly every system. You need:

首先,我删除了cx_freeze并使用了py2exe。我已经在WinXP 32位上构建了所有的东西——为了实现这个目标,它几乎可以在每个系统上运行。你需要:

  • Win XP 32-bit (or another system which you consider as minimal requirements)
  • Win XP 32位(或者您认为是最小需求的另一个系统)
  • Python 3.4 -- install from www.python.ord/download Windows x86 msi installer
  • Python 3.4——从www.python.ord/下载Windows x86 msi安装程序
  • PyWin32 -- install from sf.net pywin32-219.win32.py3.4.exe
  • PyWin32——安装自sf.net PyWin32 -219.win32.py3.4.exe
  • Qt5.5 -- install it from qt.io, also you get mingw, next add folder C:\Qt\Tools\mingw492_32\bin to your system env %PATH%.
  • Qt5.5——从Qt .io中安装,也可以获得mingw,然后添加文件夹C:\Qt\Tools\mingw492_32\bin到您的系统env %PATH%。
  • Git for Windows -- install from git-scm.com
  • Git用于Windows——安装自Git -scm.com
  • PyQt5 -- download from riverbankcomputing.co.uk win32 x86 installer and run it
  • PyQt5——从riverbankcomputing.co下载。uk win32 x86安装程序并运行它
  • SIP -- the worst intallation!
    • Download it from riverbankcomputing.co.uk,
    • 从riverbankcomputing.co.uk下载它,
    • unzip,
    • 解压缩,
    • run Git Bash,
    • Git Bash运行,
    • python configure.py -p win32-g++ ,
    • python配置。py - p win32-g + +,
    • mingw32-make.exe install.
    • mingw32-make。exe安装。
    • It fails (. You go manually to sipgen/ folder and copy sip.exe to c:\Python34. Next go to ../siplib and copy sip.pyd to c:\python34\Lib\site-packages, then
    • 失败(。您可以手动切换到sipgen/文件夹并复制sip。exe到c:\ Python34。下一个去. .sip / siplib和副本。pyd到c:\ python34 \ Lib \网站
    • strip /c/Python34/Lib/site-packages/sip.pyd
    • 带/ c / Python34 / Lib /网站/ sip.pyd
    • cp sip.h /c/Python34/include/
    • cp sip。h / c / Python34 / include /
  • 啜饮——最糟糕的语调!从riverbankcomputing.co下载它。unzip,运行Git Bash,配置python。py -p win32-g++, mingw32-make。exe安装。失败(。您可以手动切换到sipgen/文件夹并复制sip。exe到c:\ Python34。下一个去. .sip / siplib和副本。pyd到c:\python34\Lib\ Lib -packages, then strip /c/ python34 /Lib/site-packages/sip。pyd cp sip。h / c / Python34 / include /
  • py2exe -- python -m pip install py2exe
  • py2exe——python -m pip安装py2exe。
  • 7-Zip -- install from 7-zip.org as x86 exe
  • 7-Zip——从7-zip.org作为x86 exe安装
  • 7-zip extra, unpack into installed 7-zip folder, conflicts with .txt files could be ignored
  • 7-zip额外,解压到已安装的7-zip文件夹,与.txt文件的冲突可以被忽略
  • Resource Hacker -- from angusj.com -- however it's not necessary if you don't want to set to patch your .exe finally and give it a nice icon
  • 资源黑客——来自angusj.com——但是如果你不想设置你的。exe最后补丁,并给它一个漂亮的图标,这是没有必要的

Next I added setup.py to the project:

接下来,我添加设置。py项目:

from distutils.core import setup
import os, sys
import py2exe
from glob import glob
import PyQt5

NAME="ProgName"

qt_platform_plugins = [("platforms", glob(PyQt5.__path__[0] + r'\plugins\platforms\*.*'))]
data_files.extend(qt_platform_plugins)
msvc_dlls = [('.', glob(r'C:\Windows\System32\msvc?100.dll'))]
data_files.extend(msvc_dlls)
# print(data_files)

sys.argv.append('py2exe')

setup(
    data_files=data_files,
    # windows=["pyftp1.py",],
    windows=[
        {
            "script": "pyftp1.py",
            "icon_resources": [(0, "resources/favicon.ico")]
        }
    ],
    # zipfile=None,
    options={
        "py2exe": {
            "includes":["sip", "atexit",],
            # "packages": ['PyQt5'],
            "compressed": True,
            "dist_dir": "dist/" + NAME,
            # "bundle_files": 0,
            # "zipfile": None,
            "optimize": 2,
        }
    }
)

Just not to run all the actions manually, you may add Makefile

不要手工运行所有操作,您可以添加Makefile

# start settings
DIST=dist
# change NAME also in setup.py and resource/config.txt
NAME=ProgName
EXT=exe

# final name and location of the built program
FINAL=$(DIST)/$(NAME).$(EXT)

# external programs
7ZIPDIR="C:\Program Files\7-Zip"
RESHACKER="/c/Program\ Files/Resource\ Hacker/ResourceHacker.exe"

# intermediate steps

# no icon version of program 
NOICON=$(DIST)/$(NAME)_no_icon.$(EXT)

# name of .7z archive
7Z_BASENAME=$(NAME).7z
7Z=$(DIST)/$(7Z_BASENAME)

# folder with ready .exe
PROGDIR=$(DIST)/$(NAME)

all: $(FINAL)


$(FINAL): $(NOICON)
    # change icon
    "$(RESHACKER)" -addoverwrite $(NOICON), $(FINAL), resources/favicon.ico, ICONGROUP, MAINICON, 0


$(NOICON): $(7Z)
    #build autorunning sfx with default icon
    cat $(7ZIPDIR)/7zS.sfx resources/config.txt $(7Z) > $(NOICON)


$(7Z): exe
    # compress program folder to .7z
    cd $(DIST);  $(7ZIPDIR)\\\7z.exe a  $(7Z_BASENAME)  $(NAME)


exe:  $(DIST)
    # build program itself
    python setup.py py2exe


$(DIST):
    # create dist directory
    # echo $(DIST)/


clean:
    rm -rf $(DIST)/*

Now you can easily build your program itself - as a folder of files: mingw32-make.exe exe Or make a single file with correct icon: mingw32-make.exe all Or clean that all stuff: mingw32-make.exe clean

现在,您可以轻松地构建程序本身——作为文件的文件夹:mingw32-make。exe exe或创建一个带有正确图标的文件:mingw32-make。全部或全部清理:mingw32-make。exe清洁

#2


0  

you could try this:

你可以试试这个:

  1. add 'libEGL.dll' to your working folder. This is from Python3x\Lib\site-packages\PyQt5

    添加“libEGL。dll'到你的工作文件夹。这是来自Python3x \ Lib \网站\ PyQt5

  2. In cx-freeze setup.py add:

    在cx-freeze设置。py添加:

    if sys.platform == "win32": includefiles = ['libEGL.dll'] #here you should add other files if you need to

    如果系统。平台== "win32": includefiles = ['libEGL。如果需要的话,您应该在这里添加其他文件

  3. In cx-freeze setup.py link "includefiles" to build_exe_options like this:

    在cx-freeze设置。py链接“includefiles”到build_exe_options:

    build_exe_options= { ... ... 'include_files': includefiles, }

    build_exe_options = {……“include_files”:includefiles }

#1


3  

Solution.

After struggling during a lot of time with a problem I've found the solution. Many how-to do not take an account specific versions of software, or some specific modules used, or even they do not check .exe on fresh system, which has no your libraries dlls and so on. Here's working and tested solution.

在与一个问题纠缠了很长时间之后,我找到了解决办法。许多how-to都不考虑特定版本的软件,或使用的特定模块,甚至不检查新系统上的.exe,它没有库dll等。这是工作和测试的解决方案。

First, I removed cx_freeze and used py2exe. I've built all the stuff on WinXP 32-bit - for the goal it could be run on nearly every system. You need:

首先,我删除了cx_freeze并使用了py2exe。我已经在WinXP 32位上构建了所有的东西——为了实现这个目标,它几乎可以在每个系统上运行。你需要:

  • Win XP 32-bit (or another system which you consider as minimal requirements)
  • Win XP 32位(或者您认为是最小需求的另一个系统)
  • Python 3.4 -- install from www.python.ord/download Windows x86 msi installer
  • Python 3.4——从www.python.ord/下载Windows x86 msi安装程序
  • PyWin32 -- install from sf.net pywin32-219.win32.py3.4.exe
  • PyWin32——安装自sf.net PyWin32 -219.win32.py3.4.exe
  • Qt5.5 -- install it from qt.io, also you get mingw, next add folder C:\Qt\Tools\mingw492_32\bin to your system env %PATH%.
  • Qt5.5——从Qt .io中安装,也可以获得mingw,然后添加文件夹C:\Qt\Tools\mingw492_32\bin到您的系统env %PATH%。
  • Git for Windows -- install from git-scm.com
  • Git用于Windows——安装自Git -scm.com
  • PyQt5 -- download from riverbankcomputing.co.uk win32 x86 installer and run it
  • PyQt5——从riverbankcomputing.co下载。uk win32 x86安装程序并运行它
  • SIP -- the worst intallation!
    • Download it from riverbankcomputing.co.uk,
    • 从riverbankcomputing.co.uk下载它,
    • unzip,
    • 解压缩,
    • run Git Bash,
    • Git Bash运行,
    • python configure.py -p win32-g++ ,
    • python配置。py - p win32-g + +,
    • mingw32-make.exe install.
    • mingw32-make。exe安装。
    • It fails (. You go manually to sipgen/ folder and copy sip.exe to c:\Python34. Next go to ../siplib and copy sip.pyd to c:\python34\Lib\site-packages, then
    • 失败(。您可以手动切换到sipgen/文件夹并复制sip。exe到c:\ Python34。下一个去. .sip / siplib和副本。pyd到c:\ python34 \ Lib \网站
    • strip /c/Python34/Lib/site-packages/sip.pyd
    • 带/ c / Python34 / Lib /网站/ sip.pyd
    • cp sip.h /c/Python34/include/
    • cp sip。h / c / Python34 / include /
  • 啜饮——最糟糕的语调!从riverbankcomputing.co下载它。unzip,运行Git Bash,配置python。py -p win32-g++, mingw32-make。exe安装。失败(。您可以手动切换到sipgen/文件夹并复制sip。exe到c:\ Python34。下一个去. .sip / siplib和副本。pyd到c:\python34\Lib\ Lib -packages, then strip /c/ python34 /Lib/site-packages/sip。pyd cp sip。h / c / Python34 / include /
  • py2exe -- python -m pip install py2exe
  • py2exe——python -m pip安装py2exe。
  • 7-Zip -- install from 7-zip.org as x86 exe
  • 7-Zip——从7-zip.org作为x86 exe安装
  • 7-zip extra, unpack into installed 7-zip folder, conflicts with .txt files could be ignored
  • 7-zip额外,解压到已安装的7-zip文件夹,与.txt文件的冲突可以被忽略
  • Resource Hacker -- from angusj.com -- however it's not necessary if you don't want to set to patch your .exe finally and give it a nice icon
  • 资源黑客——来自angusj.com——但是如果你不想设置你的。exe最后补丁,并给它一个漂亮的图标,这是没有必要的

Next I added setup.py to the project:

接下来,我添加设置。py项目:

from distutils.core import setup
import os, sys
import py2exe
from glob import glob
import PyQt5

NAME="ProgName"

qt_platform_plugins = [("platforms", glob(PyQt5.__path__[0] + r'\plugins\platforms\*.*'))]
data_files.extend(qt_platform_plugins)
msvc_dlls = [('.', glob(r'C:\Windows\System32\msvc?100.dll'))]
data_files.extend(msvc_dlls)
# print(data_files)

sys.argv.append('py2exe')

setup(
    data_files=data_files,
    # windows=["pyftp1.py",],
    windows=[
        {
            "script": "pyftp1.py",
            "icon_resources": [(0, "resources/favicon.ico")]
        }
    ],
    # zipfile=None,
    options={
        "py2exe": {
            "includes":["sip", "atexit",],
            # "packages": ['PyQt5'],
            "compressed": True,
            "dist_dir": "dist/" + NAME,
            # "bundle_files": 0,
            # "zipfile": None,
            "optimize": 2,
        }
    }
)

Just not to run all the actions manually, you may add Makefile

不要手工运行所有操作,您可以添加Makefile

# start settings
DIST=dist
# change NAME also in setup.py and resource/config.txt
NAME=ProgName
EXT=exe

# final name and location of the built program
FINAL=$(DIST)/$(NAME).$(EXT)

# external programs
7ZIPDIR="C:\Program Files\7-Zip"
RESHACKER="/c/Program\ Files/Resource\ Hacker/ResourceHacker.exe"

# intermediate steps

# no icon version of program 
NOICON=$(DIST)/$(NAME)_no_icon.$(EXT)

# name of .7z archive
7Z_BASENAME=$(NAME).7z
7Z=$(DIST)/$(7Z_BASENAME)

# folder with ready .exe
PROGDIR=$(DIST)/$(NAME)

all: $(FINAL)


$(FINAL): $(NOICON)
    # change icon
    "$(RESHACKER)" -addoverwrite $(NOICON), $(FINAL), resources/favicon.ico, ICONGROUP, MAINICON, 0


$(NOICON): $(7Z)
    #build autorunning sfx with default icon
    cat $(7ZIPDIR)/7zS.sfx resources/config.txt $(7Z) > $(NOICON)


$(7Z): exe
    # compress program folder to .7z
    cd $(DIST);  $(7ZIPDIR)\\\7z.exe a  $(7Z_BASENAME)  $(NAME)


exe:  $(DIST)
    # build program itself
    python setup.py py2exe


$(DIST):
    # create dist directory
    # echo $(DIST)/


clean:
    rm -rf $(DIST)/*

Now you can easily build your program itself - as a folder of files: mingw32-make.exe exe Or make a single file with correct icon: mingw32-make.exe all Or clean that all stuff: mingw32-make.exe clean

现在,您可以轻松地构建程序本身——作为文件的文件夹:mingw32-make。exe exe或创建一个带有正确图标的文件:mingw32-make。全部或全部清理:mingw32-make。exe清洁

#2


0  

you could try this:

你可以试试这个:

  1. add 'libEGL.dll' to your working folder. This is from Python3x\Lib\site-packages\PyQt5

    添加“libEGL。dll'到你的工作文件夹。这是来自Python3x \ Lib \网站\ PyQt5

  2. In cx-freeze setup.py add:

    在cx-freeze设置。py添加:

    if sys.platform == "win32": includefiles = ['libEGL.dll'] #here you should add other files if you need to

    如果系统。平台== "win32": includefiles = ['libEGL。如果需要的话,您应该在这里添加其他文件

  3. In cx-freeze setup.py link "includefiles" to build_exe_options like this:

    在cx-freeze设置。py链接“includefiles”到build_exe_options:

    build_exe_options= { ... ... 'include_files': includefiles, }

    build_exe_options = {……“include_files”:includefiles }