0

I want to convert one .py file to .exe from Linux Ubuntu. I found pyinstaller for this. But when pyinstaller runs from Linux it makes file executable only for Linux and when pyinstaller runs from Windows it makes .exe file for Windows. I want to convert .exe file from Linux for Windows. So how can i make it? I need an instruction.

P.S: if i cannot do it with pyinstaller, please write other tool.

Vlad Havriuk
  • 1,291
  • 17
  • 29
  • Possible duplicate of [Cross-compiling a Python script on Linux into a Windows executable](https://stackoverflow.com/questions/2950971/cross-compiling-a-python-script-on-linux-into-a-windows-executable) – Lodi Aug 17 '18 at 16:05
  • @Lodi that question isn't answered completely – Vlad Havriuk Aug 17 '18 at 16:06
  • 1
    Yes, it is. It says that you'll need to use a tool to virtually use windows inside linux. There's no other way – Lodi Aug 17 '18 at 16:07
  • 1
    Take a look here https://www.andreafortuna.org/technology/how-to-cross-compile-a-python-script-into-a-windows-executable-on-linux/ , This article teaches how to do it – Lodi Aug 17 '18 at 16:07

1 Answers1

1

If you know how to use Docker, that may be an easy enough way to do it. The relevant docker images can be found here.

From the documentation there:

There are two containers, one for Linux and one for Windows builds. The Windows builder runs Wine inside Ubuntu to emulate Windows in Docker.

To build your application, you need to mount your source code into the /src/ volume.

The source code directory should have your .spec file that PyInstaller generates. If you don't have one, you'll need to run PyInstaller once locally to generate it.

If the src folder has a requirements.txt file, the packages will be installed into the environment before PyInstaller runs.

For example, in the folder that has your source code, .spec file and requirements.txt:

docker run -v "$(pwd):/src/" cdrx/pyinstaller-windows 

will build your PyInstaller project into dist/windows/. The .exe file will have the same name as your .spec file.

docker run -v "$(pwd):/src/" cdrx/pyinstaller-linux 

will build your PyInstaller project into dist/linux/. The binary will have the same name as your .spec file.

Zain Patel
  • 983
  • 5
  • 14