python - 在未安装 python 的情况下将 python 作为 .exe 文件运行

标签 python py2exe

我试图在没有安装 python 的系统上运行 python 文件。我正在使用 py2exe,它给我一个 .pyc 文件,它在我的系统上运行良好,但是当我把它交给一个没有 python 的 friend 时,它告诉他 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 从脚本创建可执行文件(即从 script.py 创建 script.exe)。

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

参见 py2exe package page了解详情。

关于python - 在未安装 python 的情况下将 python 作为 .exe 文件运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29972410/

相关文章:

python - 如何捕获 ctrl-c 以杀死 Flask python 脚本

python - 离散傅立叶变换在 python 中不起作用/效率很低

python - Spark XML - 使用 Excel 中的 XML

python - PIL 和 py2exe 的问题

python - 使用 py2exe 将 python selenium 脚本构建为 exe

python - Scrapy禁用重试中间件

python - 从基类调用基类方法

python - 通过 Esky 任务获取进度

python - 创建不带 MSVCP90.dll 的 Python EXE

python - 用于 Python 3.0 的 Py2exe