简体   繁体   English

如何在Ubuntu上使用py2exe(或pyinstaller)创建.exe

[英]How to create .exe using py2exe(or pyinstaller) on Ubuntu

Given: 鉴于:
- Ubuntu - Ubuntu
- py2exe and pyinstaller - Python script with setup.py (or else) - py2exe和pyinstaller - 带有setup.py(或其他)的Python脚本

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"]
}}
)

Need: 需要:
- One .exe file and maybe some .dll (I realy don't know) - 一个.exe文件,也许是一些.dll(我真的不知道)

Steps what I did: 我做的步骤:
- setup pip3 and python 3.4 ( https://askubuntu.com/questions/524399/issues-with-py2exe ) - 设置pip3和python 3.4( https://askubuntu.com/questions/524399/issues-with-py2exe
- setup py2exe for ubuntu "pip3 install py2exe" - 为ubuntu设置py2exe“pip3 install py2exe”
- run "python3.4 setup.py py2exe" And got following traceback: - 运行“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


- setup pyinstaller for ubuntu ( https://github.com/pyinstaller/pyinstaller/wiki ) - 为ubuntu设置pyinstaller( https://github.com/pyinstaller/pyinstaller/wiki
- run "pyinstaller setup.py"(same as "pyinstaller -w setup.py") and got in dist folder many files with extension .so and one file "setup" without extension - 运行“pyinstaller setup.py”(与“pyinstaller -w setup.py”相同)并在dist文件夹中获取许多扩展名为.so的文件和一个没有扩展名的“setup”文件

What am I doing wrong? 我究竟做错了什么?
How can I get .exe file under Ubuntu? 如何在Ubuntu下获取.exe文件?
Is it possible? 可能吗?

PS: I've read Python executables: py2exe or PyInstaller? PS:我读过Python可执行文件:py2exe或PyInstaller? by I didn't find answer. 我没有找到答案。

You cannot use py2exe on Ubuntu or Linux in general. 一般来说,你不能在Ubuntu或Linux上使用py2exe。 You cannot use it on Mac either. 你不能在Mac上使用它。 It is a Windows-only utility! 它是一个仅限Windows的实用程序! You have to use it within Windows, whether that be in a Windows virtual machine or an actual Windows machine. 您必须在Windows中使用它,无论是在Windows虚拟机还是实际的Windows机器中。

As for PyInstaller, please read the docs: 至于PyInstaller,请阅读文档:

Can I use PyInstaller as a cross-compiler? 我可以使用PyInstaller作为交叉编译器吗?

  • Can I package Windows binaries while running under Linux? 我可以在Linux下运行时打包Windows二进制文件吗?

    No, this is not supported. 不,这不受支持。 Please use Wine for this, PyInstaller runs fine in Wine. 请使用Wine,PyInstaller在Wine中运行良好。 You may also want to have a look at this thread in the mailinglist. 您可能还想查看邮件列表中的此主题。 In version 1.4 we had build in some support for this, but it showed to work only half. 在1.4版本中,我们已经为此建立了一些支持,但它只显示了一半。 It would require some Windows system on another partition and would only work for pure Python programs. 它需要在另一个分区上安装一些Windows系统,并且只适用于纯Python程序。 As soon as you want a decent GUI (gtk, qt, wx), you would need to install Windows libraries anyhow. 只要你想要一个像样的GUI(gtk,qt,wx),你无论如何都需要安装Windows库。 So it's much easier to just use Wine. 因此,使用Wine更容易。 - source - 来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM