2

问题

尝试运行使用 cx_Freeze 构建的 .exe 时出现以下错误:

ImportError:没有名为“pythoncom”的模块

我该如何解决这个问题?

cx_Freeze:主脚本中的 Python 错误

附加信息

设置:

  • Windows 7 企业版 64 位
  • WinPython-64bit-3.5.2.3Qt5(Python 3.5.2 64 位)
  • cx_Freeze 5.0

设置.py:

import os
import sys
from cx_Freeze import setup, Executable


os.environ['TCL_LIBRARY'] = r"C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\tcl\tcl8.6" 
os.environ['TK_LIBRARY'] = r"C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\tcl\tk8.6" 


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

options = {
    'build_exe': {
        'excludes': ['gtk', 'PyQt4', 'Tkinter'],
        'includes': ['pythoncom']
    }
}


executables = [
    Executable('GUI.py', base=base)
]


setup(name='GUI',
      version='0.1',
      description='GUI test',
      executables=executables,
      options=options
      )

GUI.py 中的导入*

*其中一部分

from bs4 import BeautifulSoup
import requests
import win32com.client, pythoncom

from PyQt5 import QtCore, QtGui, QtWidgets

from matplotlib import use as MPLuse
MPLuse("Qt5Agg",force=True)

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure

import seaborn as sns

使用“pythoncom”或“pywin”构建输出行:

m pythoncom                 C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\pythoncom35.dll
...
copying C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\pythoncom35.dll -> build\exe.win-amd64-3.5\pythoncom35.dll

..
P pywin                     C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\Pythonwin\pywin\__init__.py
P pywin.dialogs             C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\Pythonwin\pywin\dialogs\__init__.py
m pywin.dialogs.list        C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\Pythonwin\pywin\dialogs\list.py
m pywin.dialogs.status      C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\Pythonwin\pywin\dialogs\status.py
P pywin.mfc                 C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\Pythonwin\pywin\mfc\__init__.py
m pywin.mfc.dialog          C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\Pythonwin\pywin\mfc\dialog.py
m pywin.mfc.object          C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\Pythonwin\pywin\mfc\object.py
m pywin.mfc.thread          C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\Pythonwin\pywin\mfc\thread.py
m pywin.mfc.window          C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\Pythonwin\pywin\mfc\window.py
m pywintypes                C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\pywintypes35.dll

..

copying C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\pywintypes35.dll -> build\exe.win-amd64-3.5\pywintypes35.dll

构建过程中的错误:

没有任何

我还尝试过什么?

  1. 构建没有'includes': ['pythoncom']. 结果是一样的。
  2. 'packages': ['pythoncom']. 结果是一样的。
  3. 'includes': ['pywin32']. 将ImportError: No module named 'pywin32'在构建期间获得。
  4. 'packages': ['pywin32']. 将ImportError: No module named 'pywin32'在构建期间获得。
4

0 回答 0