运行 pythons 作为 .exe 文件,未安装 python

Run pythons as .exe files without python installed

我正在尝试在未安装 python 的系统上 运行 一个 python 文件。我正在使用 py2exe,它给了我一个 .pyc 文件,在我的系统上 运行 没问题,但是当我把它给一个没有 python 的朋友时,它告诉他 Windows 不能运行 文件。

我的 setup.py 文件包含这个;

from distutils.core import setup
import py2exe

setup(console=['PyVersionControl.py'])

当我在命令行中运行 py2exe时,这是输出

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\chdick>python setup.py py2exe
running py2exe

  3 missing Modules
  ------------------
? readline                            imported from cmd, code, pdb
? win32api                            imported from platform
? win32con                            imported from platform
Building 'dist\PyVersionControl.exe'.
Building shared code archive 'dist\library.zip'.
Copy c:\windows\system32\python34.dll to dist
Copy C:\Python34\DLLs\pyexpat.pyd to dist\pyexpat.pyd
Copy C:\Python34\DLLs\_ctypes.pyd to dist\_ctypes.pyd
Copy C:\Python34\DLLs\unicodedata.pyd to dist\unicodedata.pyd
Copy C:\Python34\DLLs\_hashlib.pyd to dist\_hashlib.pyd
Copy C:\Python34\DLLs\_socket.pyd to dist\_socket.pyd
Copy C:\Python34\DLLs\_tkinter.pyd to dist\_tkinter.pyd
Copy C:\Python34\DLLs\_bz2.pyd to dist\_bz2.pyd
Copy C:\Python34\DLLs\select.pyd to dist\select.pyd
Copy C:\Python34\DLLs\_ssl.pyd to dist\_ssl.pyd
Copy C:\Python34\DLLs\_lzma.pyd to dist\_lzma.pyd
Copy DLL C:\Python34\DLLs\tk86t.dll to dist\
Copy DLL C:\Python34\DLLs\tcl86t.dll to dist\

C:\Users\chdick>

Py2exe 不支持 Python 3.4.

标题告诉你,只针对Python的第二版。

您需要使用 py2exe 从脚本创建可执行文件(即从 script.py 创建 script.exe)。

如果您安装了正确版本的 py2exe,您应该能够输入 python -m py2exe.build_exe script.py

详情见py2exe package page