1

Say, I have the following cython module renamed_module.pyx. This module contains all my cython code which include C and Python functions. Normally in development below is how I compile and run renamed_module.pyx.

  1. A python file called setup.py that calls cython to convert my pyx modules into C code.

Setup.py code:

from distutils.core import setup
from Cython.Build import cythonize

setup(
    name="appname",
    ext_modules=cythonize(['renamed_module.pyx', 'other1.pyx', 'other2.pyx',  'other3.pyx']),
    language_level=3)
  1. I have another python file called run_renamed_module.py with the following code:

run_renamed_module.py:

import renamed_module
import os
import sys

sys.path.insert(0, os.path.abspath("."))

renamed_module.startingfunction()
  1. Finally I compile it as following which works perfectly: python Setup.py build_ext --inplace && python run_renamed_module.py

Question

Now, I would like to convert my renamed_module.pyx into a standalone executable or a *.exe file that would open my cython GUI App.

After doing some research, I was able to first convert my renamed_module.pyx code into C code using cython renamed_module.pyx --embed -o renamed_module_comp.c

and then compile it to a binary file using gcc -c -DMS_WIN64 -shared -pthread -Wall -IC:/Users/[username]/AppData/Local/Programs/Python/Python39/Include -LC:/Users/[username]/AppData/Local/Programs/Python\Python39\libs -o app.exe renamed_module_comp.c.

With these two steps, I fall into no errors and they compile just fine. But now when I attempt to execute app.exe, I get the following error:

This app can't run on your PC. To find a version for your PC, check with the software publisher.

As reported/commented by other developers on the web, app.exe seem to be a DLL file. So, I tried to copy app.exe into an external folder, open python terminal from that directory, and call import app. With that I get:

ImportError: DLL load failed while importing app: %1 is not a valid Win32 application.

Unfortunately I don't know where to go from here. Any direction is really appreciated.

OS: Windows 10 x64
Python Version: Python 3.9.1
Cython Version: Cython version 0.29.23
GCC Version: gcc.exe (GCC) 9.2.0
GUI Libs: PyQT5 - Tkinter and pysimplegui 

Summary of the question: I basically, want to compile my cython GUI app into a standalone executable program.

neehack
  • 21
  • 3
  • 1
    I'm not sure exactly why your program isn't running. However you are unlikely to succeed in making a truly standalone executable. See https://stackoverflow.com/questions/52959902/make-executable-file-from-multiple-pyx-files-using-cython. Cython is not designed for this. You should use one of the tools that is designed for this instead – DavidW Jan 09 '22 at 09:26
  • Your application almost certainly depends on a bunch of other libraries (for example, the GUI library) and you can't embed those into your executable. Therefore it will not be standalone. – DavidW Jan 09 '22 at 09:32
  • @DavidW I am using `PyQt5, tkinter and pysimplegui` for GUI stuff – neehack Jan 09 '22 at 18:04
  • I am okay, to not bundle everything into one executable. If the GUI is required to be separate, I am fine with that – neehack Jan 09 '22 at 18:09
  • It is not clear, what gcc-port you are using. You probably can follow steps in this question: https://stackoverflow.com/q/70654722/5769463 – ead Jan 10 '22 at 15:20

0 Answers0