【发布时间】:2020-06-01 18:51:36
【问题描述】:
我是 python 编程的新手,我想创建一个 .exe 文件以及第三方 python 包。我的要求是,如果我将项目的源代码提供给任何开发人员,他/她将只需运行python setup.py build 以便创建 .exe 文件。我在setup.py 文件中也提到了install_requires,提到了第三方包,但我得到了错误。我在代码下方提供。这个要求类似于 java,基于 maven 的应用程序,用户运行 pom.xml 来创建可执行文件。
import sys
from cx_Freeze import setup, Executable
includefiles = []
includes = []
excludes = ['Tkinter']
packages = ['configparser == 4.0.2', 'colorama == 0.4.3', 'xlsxwriter == 1.2.7']
build_exe_options = {'includes':includes,'packages':packages, 'excludes':excludes, 'include_files':includefiles}
base = None
setup(name = 'Testing',
version = '0.1',
author = 'DD Mishra',
description = 'A simple application',
install_requires = ['configparser == 4.0.2', 'colorama == 0.4.3', 'xlsxwriter == 1.2.7'],
options = {'build_exe': build_exe_options},
executables = [Executable('main.py', base=base)]
)
我正在使用命令python setup.py build。首先,我想安装所有必需的包,如 configparser、colorama、xlsxwriter,然后应该创建 exe。一切都应该自动发生,无需使用pip 命令手动安装包。
根据我在运行命令python setup.py build 时的上述设置,我收到以下错误。
running build running build_exe Traceback(最近一次调用最后一次):
文件“setup.py”,第 13 行,在 setup(name = 'Testing', 文件 "C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\dist.py", 行 340,在设置中 distutils.core.setup(**attrs) 文件“C:\devsoftwares\Python38\lib\distutils\core.py”,第 148 行,在设置中 dist.run_commands() 文件“C:\devsoftwares\Python38\lib\distutils\dist.py”,第 966 行,在 运行命令 self.run_command(cmd) 文件“C:\devsoftwares\Python38\lib\distutils\dist.py”,第 985 行,在 运行命令 cmd_obj.run() 文件“C:\devsoftwares\Python38\lib\distutils\command\build.py”,第 135 行, 运行中 self.run_command(cmd_name) 文件“C:\devsoftwares\Python38\lib\distutils\cmd.py”,第 313 行,在 运行命令 self.distribution.run_command(command) 文件“C:\devsoftwares\Python38\lib\distutils\dist.py”,第 985 行,在 运行命令 cmd_obj.run() 文件“C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\dist.py”,行 211,运行中 freezer.Freeze() 文件 "C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\freezer.py", 第 610 行,冻结 self.finder = self._GetModuleFinder() 文件 "C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\freezer.py", 第 354 行,在 _GetModuleFinder 中 finder.IncludeModule(name) 文件“C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\finder.py”,行 631,在 IncludeModule 中 模块 = self._ImportModule(名称,deferredImports,文件“C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\finder.py”,行 348,在 _ImportModule 中 raise ImportError("No module named %r" % name) ImportError: No module named 'configparser == 4.
0.2'
【问题讨论】:
标签: java python python-3.x cx-freeze