我试图在Python中用cx_Freeze
创建的可执行文件中包含所有依赖项,这样如果可执行文件在没有安装软件包/模块的任何机器上运行,则没有错误。是的,我们可以像我一样明确地包含这些包。但我需要自动包含所有依赖项的内容。
我已将此代码用于setup.py
from cx_Freeze import setup, Executable
includefiles = ["log_filename.txt"] # include any files here that you wish
includes = []
excludes = []
packages = ["lxml"]
exe = Executable(
script = "app.py", # the name of your main python script goes here
initScript = None,
base = None, # if creating a GUI instead of a console app, type "Win32GUI"
targetName = "app.exe", # this is the name of the executable file
copyDependentFiles = True,
compress = True,
appendScriptToExe = True,
appendScriptToLibrary = True,
icon = None # if you want to use an icon file, specify the file name here
)
setup(
name = "ap", # program name
version = "0.1",
description = 'app',
author = "",
author_email = "",
options = {"build_exe": {"excludes":excludes,"packages":packages,
"include_files":includefiles}},
executables = [exe]
)
我使用了find_packages()
但是它会导致一些错误。
错误:
Traceback (most recent call last):
File "setup.py", line 29, in <module>
executables = [exe]
File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 362, in setup
distutils.core.setup(**attrs)
File "C:\Python27\lib\distutils\core.py", line 112, in setup
_setup_distribution = dist = klass(attrs)
File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 24, in __init__
distutils.dist.Distribution.__init__(self, attrs)
TypeError: unbound method __init__() must be called with Distribution instance as first argument (got Distribution instance instead)
请帮助