在 cx freeze 中制作 msi - reportlab 中的模块

Posted

技术标签:

【中文标题】在 cx freeze 中制作 msi - reportlab 中的模块【英文标题】:Making msi in cx freeze - module in reportlab 【发布时间】:2014-08-20 19:38:55 【问题描述】:

我正在尝试在 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 文件时,它会引发此错误。

【问题讨论】:

【参考方案1】:

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

【讨论】:

以上是关于在 cx freeze 中制作 msi - reportlab 中的模块的主要内容,如果未能解决你的问题,请参考以下文章

使用 cx_Freeze 构建 msi:ValueError:FCI 错误 1

使用 cx_Freeze 创建 MSI 时可用的 bdist_msi 选项

CX_Freeze - 构建具有管理员权限的 .msi

使用 cx_freeze 和 bdist_msi 为 PySide 应用程序创建 MSI

在 cx_freeze 中创建的 msi 不安装程序

.msi 使用 cx_Freeze 的快捷方式