Skip to main content
 首页 » 编程设计

python之在 cx 卡住中制作 msi之reportlab 中的模块

2025年05月04日13zhenyulu

我正在尝试在 cx_freeze 中制作一个可分发的 python 脚本。当我运行它时,出现此错误:

ImportError: No module named lib 

我程序中引用的行是

from reportlab.lib import colors, utils 

我没有在我的 setup.py 中指定包。这个特定程序的输出是用 Reportlab 编写的 pdf 报告。我还使用 PyQt4、matplotlib、numpy 和 mpl_toolkits。在其中的大多数中,我导入了特定的模块。有没有办法改变包裹?或者任何其他方式来做我想做的事?目标是一个可安装的程序,以便同事可以在我不在的情况下生成报告,而无需实际安装 Python 和装备。


预计到达时间

这是我的 setup.py:

import sys 
from cx_Freeze import setup, Executable 
 
base = None 
 
build_exe_options = {"packages": ["os",'sys', 'PyQt4','reportlab', 'csv', 'numpy', 'matplotlib']} 
 
 
if sys.platform == 'win32': 
    base = 'Win32GUI' 
 
setup(  name = "XY grouped plots", 
        version = "0.1", 
        description = "Contact <myworkemail> with questions", 
        options = {"build_exe" : build_exe_options}, 
        executables = [Executable("XY_grouped_plots.pyw", base=base)]) 

下面是我在程序中使用的导入:

import sys 
from PyQt4 import QtGui, QtCore 
from PyQt4.QtGui import *   #yes, I know this should be covered above 
from PyQt4.QtCore import * #but for some reason when I only do that, it gives me errors.  
from reportlab.lib import colors, utils 
import csv 
import numpy as np 
from reportlab.pdfgen import canvas 
from reportlab.lib.pagesizes import letter, landscape 
from reportlab.lib.units import inch 
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Image, PageBreak, KeepTogether 
from reportlab.lib.styles import ParagraphStyle as PS 
from reportlab.lib.enums import TA_CENTER 
from reportlab.platypus.paragraph import Paragraph 
import matplotlib.pyplot as plt 
import matplotlib as mpl 

这是我在添加上述包时遇到的错误:

raise ImportError("No module named %r" %subModuleName) 
ImportError: No module named 'PyQt4.uic.port_v3.proxy_base' 

我的导入是否过于广泛?当我让 cx_freeze 选择导入时,我遇到了 reportlab 的问题(并且在构建 msi 文件时没有错误)。现在,当我尝试制作 msi 文件时,它会抛出此错误。

请您参考如下方法:

我遇到了这个问题,在我从包中删除'PyQt4'之后,构建成功!