:
- Ubuntu
- py2exe和pyinstaller
- 使用setup.py(或其他)
from distutils.core import setup
import py2exe
import os
setup(
version = "1.0",
description = 'foo',
url = "",
name = "foo",
console=[{
"script":"main.py",
"dest_base":"foo",
}],
zipfile = "shared.dll",
options = {"py2exe":{
'bundle_files': 1,
'optimize': 2,
"dll_excludes": ['MSVCP90.dll', 'msvcr71.dll', "IPHLPAPI.DLL", "NSI.dll", "WINNSI.DLL", "WTSAPI32.dll"],
"includes": ["utils"]
}}
)
需要:
- 一个.exe文件,也许还有一些.dll(我真的不知道)
我做的步骤:
- 设置pip3和python 3.4(https://askubuntu.com/questions/524399/issues-with-py2exe)
- 为ubuntu设置py2exe“pip3 install py2exe”
- 运行“python3.4 setup.py py2exe”并获得以下追溯:
Traceback (most recent call last):
File "setup.py", line 2, in <module>
import py2exe
File "/usr/local/lib/python3.4/dist-packages/py2exe/__init__.py", line 9, in <module>
patch_distutils()
File "/usr/local/lib/python3.4/dist-packages/py2exe/patch_distutils.py", line 68, in patch_distutils
from . import distutils_buildexe
File "/usr/local/lib/python3.4/dist-packages/py2exe/distutils_buildexe.py", line 91, in <module>
from . import runtime
File "/usr/local/lib/python3.4/dist-packages/py2exe/runtime.py", line 3, in <module>
from .dllfinder import Scanner, pydll
File "/usr/local/lib/python3.4/dist-packages/py2exe/dllfinder.py", line 5, in <module>
from . import _wapi
File "/usr/local/lib/python3.4/dist-packages/py2exe/_wapi.py", line 4, in <module>
_kernel32 = WinDLL("kernel32")
NameError: name 'WinDLL' is not defined
- 为ubuntu设置pyinstaller(https://github.com/pyinstaller/pyinstaller/wiki)
- 运行“pyinstaller setup.py”(与“pyinstaller -w setup.py”相同)并在dist文件夹中获取许多扩展名为.so的文件和一个没有扩展名的“setup”文件
我做错了什么?
如何在Ubuntu下获得.exe文件?
有可能吗?
PS:我读过Python executables: py2exe or PyInstaller?,但我找不到答案。
答案 0 :(得分:5)
一般情况下,不能在Ubuntu或Linux上使用py2exe。你不能在Mac上使用它。它是仅限Windows 实用程序!您必须在Windows中使用它,无论是在Windows虚拟机还是实际的Windows机器中。
至于PyInstaller,请阅读文档:
我可以使用PyInstaller作为交叉编译器吗?
我可以在Linux下运行时打包Windows二进制文件吗?
不,这不受支持。请使用Wine,PyInstaller在Wine中运行良好。您可能还想查看邮件列表中的此主题。在1.4版本中,我们已经为此建立了一些支持,但它只显示了一半。它需要在另一个分区上安装一些Windows系统,并且只适用于纯Python程序。只要你想要一个像样的GUI(gtk,qt,wx),你无论如何都需要安装Windows库。因此,使用Wine会更容易。 - source