在Windows上如何制作一个单文件可执行的python 2.7 x64文件?

2024-04-29 05:39:00 发布

您现在位置:Python中文网/ 问答频道 /正文

看到这个后:Single-File Stand-alone Python 2.7.9 for Windows

我想为最新的python2.7.11x64做一个类似的事情,但因为py2exe不支持x64模式下的单个文件打包。我使用了cx_freeze,并成功地生成了一个包,但是cx_freeze没有单个文件选项。在

所以我尝试了IExpress,和7-zip sfx模块,但是它们都不能运行py.exe文件在同一个控制台中,它们无法将参数传递到提取的exe文件。我还有别的选择吗?在

下面是我的python脚本: https://gist.github.com/oglops/a641b0185ed903ab1d1c

如果你尝试py.exe文件从最初的作者那里,它有一些命令行参数,并且运行在同一个控制台中,所以可以这样使用它

py.exe  <some py script>

Tags: 文件pyforwindows模式事情exefile
2条回答

您可以使用PyInstaller来实现这一点,但是您必须解决它钩住各种模块的一些方法,因为PyInstaller希望您的目标是一个自包含的应用程序,而不是Python解释器。我最近把Shuman引用的代码移到了一个GitHub项目中,该项目使用PyInstaller构建python2.7、3.5和3.6的32位和64位变体的独立版本。见https://github.com/manthey/pyexe。在

首先,您需要安装pyinstaller,可以这样得到:

pip install pyinstaller

然后从python文件夹中,generate the spec如下所示:

^{pr2}$

打开spec文件并确保所有内容都正确。在

然后使用规范构建应用程序,如下所示:

pyinstaller.py  onefile myscriptsname.spec

如果在构建规范时遇到以下错误:

ImportError: No module named six

然后还需要使用以下命令安装six

pip install six

有关six的详细信息:

Six is a Python 2 and 3 compatibility library. It provides utility functions for smoothing over the differences between the Python versions with the goal of writing Python code that is compatible on both Python versions. See the documentation for more information on what is provided.

Six supports every Python version since 2.6. It is contained in only one Python file, so it can be easily copied into your project. (The copyright and license notice must be retained.)

相关问题 更多 >