I am working on a python3.7 project that involves several modules and import from distributed packages (pyside2, scipy,...). The project was developped, cythonized and compiled succesfully under ubuntu. My task now is to create a .exe file for windows 10.
I am trying to apply on windows 10 the same cythonize-and-compile procedure that worked on ubuntu :
I cythonized all my modules except the main.py with :
python cythonizer.py build_ext --inplace
cythonizer.py containing :
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [
Extension("datatools", ["datatools.py"]),
Extension("logger_conf", ["logger_conf.py"]),
Extension("serialization", ["serialization.py"]),
Extension("UimainWindow", ["UimainWindow.py"]),
Extension("UiprojectsFrame_newProject", ["UiprojectsFrame_newProject.py"]),
Extension("UiprojectsFrame_projectInfo", ["UiprojectsFrame_projectInfo.py"]),
Extension("UiprojectsFrame", ["UiprojectsFrame.py"]),
Extension("units_and_formats", ["units_and_formats.py"]),
]
for e in ext_modules:
e.cython_directives = {'language_level': "3"}
setup(
name = 'aircraft2020-v0.10',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
Then I cythonized my main module with the embed option :
cython main.py --embed -3
Doing this I produced .c files from my .py files. The next step is to compiled the files. On ubuntu I had used gcc succesfully, on windows 10 the computer doesn't have gcc but has visual studio, so I tried:
cl.exe /nologo /Ox /MD /W3 /GS- /DNDEBUG -I{PythonPath}\include -I{PythonPath}\PC {all_my_.c_files_here} /link /OUT:"myProgram.exe" /SUBSYSTEM:CONSOLE /MACHINE:X86 /LIBPATH:{PythonPath}\libs /LIBPATH:{PythonPath}\PCbuild
{PythonPath} and {all_my_.c_files_here} are actually very long paths and list, so I didn't copy it fully here for readability.
This compiles a .exe. But trying to executes it crashes instantly. Executing it in a command prompt, it stops on an error indicating it cannot find the first module that is called for import :
Traceback (most recent call last):
File "main.py", line 11, in init main
ModuleNotFoundError: No module named 'serialization'
If I move the .py source files to the folder it works! But obviously i don't want the source file in the realeased files. I guess something is wrong in the way the modules are imported in the compiled executable. Anyone knows what I am missing?
Thank you for your help!
EDIT : thanks to ead's comment I understood where I got confused. Usually under linux I was not understanding why I was not getting .so files, and supposed cl would put everything in the .exe.
In fact under windows the .so files are .pyd files. the cl command should be used to compile only main.c and not the other .c files.
Then simply putting the .pyd files in the same folder as the .exe will make it work.