创建一个不需要 pythonXX.dll 的独立 Windows exe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/707242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create a standalone windows exe which does not require pythonXX.dll
提问by alexroat
is there a way to create a standalone .exe from a python script. Executables generated with py2exe can run only with pythonXX.dll. I'd like to obtain a fully standalone .exe which does not require to install the python runtime library. It looks like a linking problem but using static library instead the dynamic one and it would be also useful to apply a strip in order to remove the unused symbols.
有没有办法从 python 脚本创建一个独立的 .exe。使用 py2exe 生成的可执行文件只能使用 pythonXX.dll 运行。我想获得一个完全独立的 .exe,它不需要安装 python 运行时库。它看起来像一个链接问题,但使用静态库而不是动态库,应用条带以删除未使用的符号也很有用。
Any idea ?
任何的想法 ?
Thanks.
谢谢。
Alessandro
亚历山德罗
回答by Jason Coon
You can do this in the latest version of py2exe...
Just add something like the code below in your setup.py
file (key part is 'bundle_files': 1).
您可以在最新版本的 py2exe 中执行此操作...
只需在您的setup.py
文件中添加类似以下代码的内容(关键部分是“bundle_files”:1)。
To include your TkInter package in the install, use the 'includes' key.
要在安装中包含您的 TkInter 包,请使用“includes”键。
distutils.core.setup(
windows=[
{'script': 'yourmodule.py',
'icon_resources': [(1, 'moduleicon.ico')]
}
],
zipfile=None,
options={'py2exe':{
'includes': ['tkinter'],
'bundle_files': 1
}
}
)
回答by Ignacio Vazquez-Abrams
Due to how Windows' dynamic linker works you cannot use the static library if you use .pyd or .dll Python modules; DLLs loaded in Windows do not automatically share their symbol space with the executable and so require a separate DLL containing the Python symbols.
由于 Windows 的动态链接器的工作方式,如果您使用 .pyd 或 .dll Python 模块,则不能使用静态库;在 Windows 中加载的 DLL 不会自动与可执行文件共享它们的符号空间,因此需要一个包含 Python 符号的单独 DLL。
回答by Ryan Ginstrom
If your purpose of having a single executable is to ease downloading/emailing, etc., I've solved this by bundling the py2exe output using Inno Setup. This is actually better than having a single executable, because rather than providing an executable file that can be dropped into some directory, a well behaved Windows application will provide an uninstaller, show up in the Add/Remove Programs applet, etc. Inno handles all this for you.
如果您拥有单个可执行文件的目的是简化下载/发送电子邮件等,我已经通过使用Inno Setup捆绑 py2exe 输出解决了这个问题。这实际上比拥有单个可执行文件要好,因为与其提供一个可以放入某个目录的可执行文件,一个表现良好的 Windows 应用程序将提供一个卸载程序,显示在添加/删除程序小程序中,等等。 Inno 处理所有这给你。
回答by Mark Ramm
Another solution is to create a single exe with python and all your dependencies installed inside of it, including the python.dll. There's a bit of magic in the wrapper, but it just works. The details are here:
另一种解决方案是使用 python 和其中安装的所有依赖项创建一个 exe,包括 python.dll。包装器中有一些魔法,但它确实有效。详细信息在这里:
http://code.google.com/p/pylunch/downloads/detail?name=PyLunch-0.2.pdf
http://code.google.com/p/pylunch/downloads/detail?name=PyLunch-0.2.pdf
回答by Aziz
This is not the best way to do it, but you might consider using executable SFX Archive with both the .exe and .dll files inside, and setting it to execute your .exe file when it's double clicked.
这不是最好的方法,但您可以考虑使用包含 .exe 和 .dll 文件的可执行 SFX 存档,并将其设置为在双击时执行您的 .exe 文件。