2

I wrote a python program in windows, then used pyinstaller to make it an .exe file. but the python program won't work in linux. why?

K7AAY
  • 16,864
  • 9
  • 45
  • 77
wtb
  • 21
  • 1
  • 3
  • 4
    read the errors when you run the executable on the command line. PyInstaller is not designed to really be cross-platform you have to crossbuild and use different binary libraries underneath the hood to make it work in Linux, if you're going to write a python program in Windows write it as pure Python and then just copy the application without wrapping it in PyInstaller into the Linux environment and run it with Python on-system or in a venv. – Thomas Ward Jan 30 '20 at 18:00
  • Also, check your Python versions. A Python app written for 2.7 generally will not work in 3.6, for example. – K7AAY Jan 30 '20 at 18:44
  • Does this answer your question? [Is there a way to run .exe in Ubuntu?](https://askubuntu.com/questions/653336/is-there-a-way-to-run-exe-in-ubuntu) – karel Jan 31 '20 at 04:19
  • 1
    Possible duplicate of [Executing script from shell problem](https://askubuntu.com/q/333212) – karel Jan 31 '20 at 04:25

2 Answers2

4

It's very likely the program you wrote will work in Ubuntu, but because Linux and Windows have very different API structure, you would need to recompile or run the program in a Python interpreter on the Linux system to have it work. Linux in general doesn't recognize Windows .exe files, though if you have Wine installed, your system may attempt to run the program as if it were a Windows program, using Wine to service its system calls -- and this might even work, depending how your pyinstaller structures the executable.

Zeiss Ikon
  • 5,078
  • 5
  • 18
  • 34
2

As mentioned in other answer try running in Python interpreter before compiling.

It is likely some code will have to be changed. For example if your original program contains:

INPUT_FNAME='\Documents\python_datain\today.csv

It would have to be change to:

INPUT_FNAME='~/Documents/python_datain/today.csv'

If it's low level python and does such things as moving mouse on screen, closing popup browser windows and adjusting screen brightness and color temperature many changes will be needed with added calls to xdotool, xrandr and possibly wmctrl.

WinEunuuchs2Unix
  • 99,709
  • 34
  • 237
  • 401
  • And Windows has different line endings, as well. – Davidw Jan 31 '20 at 02:21
  • 1
    @Davidw good point about `\r` in Windows vs. `\n` in Linux as I believe you mean. We could go on to say how `Gtk` doesn't support some features in Windows which it supports in Linux. – WinEunuuchs2Unix Jan 31 '20 at 03:19