How do I create a Windows executable with PyInstaller on Ubuntu?

22,552

Solution 1

Obviously the binary executable generated by PyInstaller on Linux only runs on Linux and not on other operating systems like Windows. The file name extension is irrelevant here.

According to the PyInstall FAQ you cannot use it to cross-compile for different platforms either, but running PyInstall inside Wine is supposed to achieve what you want:

  1. Can I use PyInstaller as a cross-compiler?
    1. 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.

From what I understand, you'll need to install PyInstall inside a Wine environment like you would in Windows and then use it like you would on a native Windows system. Please refer to How can I install Windows software or games? for an overview of how to get started with Wine on Ubuntu.

Solution 2

You can try Python Packager

The git homepage gives the instruction (python 2.7):

wget "http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi" 
wget "http://nchc.dl.sourceforge.net/project/pywin32/pywin32/Build%20218/pywin32-218.win32-py2.7.exe"
build_environment/create.sh
export WINEPREFIX=/tmp/path-outputted-from-create
wine start python-2.7.3.msi
wine pywin32-218.win32-py2.7.exe
build_environment/freeze.sh
./package sample-application/src/main.py MySampleProgram

This will build a separate wine environment and installs Python 2.7 as mentioned. In case you need another version, got to the python homepage and download your version.

You can also follow this instruction which downloads a wine-clone:

git clone https://github.com/paulfurley/python-windows-packager
./python-windows-packager/package.sh /path/to/myProject
Share:
22,552

Related videos on Youtube

tabibito
Author by

tabibito

co d e

Updated on September 18, 2022

Comments

  • tabibito
    tabibito over 1 year

    I created a game using pygame, and I wish to export it to a .exe file. I've used pyinstaller for this, as it is available for Ubuntu. When I run the --onefile game, it works perfectly fine (on my ubuntu computer). However, when I send it to my friend who has windows, it is NOT a Windows executable, but simply a "file" without any extension. He cannot run it. Renaming it Game.exe has not worked either.

    I'm out of ideas... can anyone help?

    • tabibito
      tabibito about 8 years
      PyInstaller's purpose is to create a .exe file from a .py file, isn't it?
    • Eduardo Cola
      Eduardo Cola about 8 years
      Under Windows. But under Linux it produces Linux binaries, of course.
    • Eduardo Cola
      Eduardo Cola about 8 years
      You could run pyinstaller's Windows version through Wine. Maybe that'll do it.
    • tabibito
      tabibito about 8 years
      I don't think there is a windows version, I think it just checks your operating system and then installs it according to which one you are using. PyInstaller only comes in a zip or targz.
  • frederickjh
    frederickjh almost 3 years
    Just a heads up, as of late 2018 the maintainer of the Python Packager says is one on the open issues on the project that he has abandoned it.