6
votes

Given:
- Ubuntu
- py2exe and pyinstaller - Python script with setup.py (or else)

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)

Steps what I did:
- setup pip3 and python 3.4 (https://askubuntu.com/questions/524399/issues-with-py2exe)
- setup py2exe for ubuntu "pip3 install py2exe"
- run "python3.4 setup.py py2exe" And got following traceback:

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)
- 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

What am I doing wrong?
How can I get .exe file under Ubuntu?
Is it possible?

PS: I've read Python executables: py2exe or PyInstaller? by I didn't find answer.

1
Why do you want to create an .exe file on Ubuntu? Won't it be better to do it on Windows??ForceBru
I want create .exe on Ubuntu and pull in on Windows machine. Yes, it's possible to create it on Windows, but not in my case (do not ask me why please)Yuriy Leonov
If I were you I would use a virtual machine. If that's not an option, try to install windows python in wine. You would kill lotsa time if you try to do it in any other way.Hennadii Madan
pyinstall faq says you should use wine github.com/pyinstaller/pyinstaller/wiki/FAQlikeon

1 Answers

7
votes

You cannot use py2exe on Ubuntu or Linux in general. You cannot use it on Mac either. It is a Windows-only utility! You have to use it within Windows, whether that be in a Windows virtual machine or an actual Windows machine.

As for PyInstaller, please read the docs:

Can I use PyInstaller as a cross-compiler?

  • Can I package Windows binaries while running under Linux?

    No, this is not supported. Please use Wine for this, PyInstaller runs fine in 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. It would require some Windows system on another partition and would only work for pure Python programs. As soon as you want a decent GUI (gtk, qt, wx), you would need to install Windows libraries anyhow. So it's much easier to just use Wine. - source