Can the game engine read .pyd file?


I built an C++ extension module for python to help my algos. The result is a .pyd file (I’m on windows) wich works fine when I test it: I can import it and use the functions inside.
However the game engine does not seem to be able to read this file. It says: "No module named myModule"
The path of import should be correct (my algocore imports the module and other python files from the same location).

So is the game engine unable to read this type of file? Or do I need to build my module in a different way?

Edit: Question that may be related: What python version is the game engine using? (My module is compiled for 3.6)

1 Like

I can get a C++ extension to run fine (under linux, and on the game servers - which are also running linux) by compiling to a .so shared library file.
But I believe .pyd files are for use in windows, so it may be troublesome getting it to work on the game servers.

Thanks for your answer!
I was afraid of that…
So now I have to find a way to compile .so file from windows

You will likely have to install something like minGW so you can compile using gcc instead of windows cl.exe. You could then specify the compiler to use your setup file for python build. I have not tested this but I think it would work.

Personally though, I will probably just copy my code to a linux environment and build it there. There will probably be less room for errors.

1 Like

Thank you for the suggestions! :slight_smile:

I will look through that this WE

So I just finished most of this myself (creating py source files) and it was much much easier to just run the build on a linux environment.

From the python docs:

To cross-compile, you must download the Python source code and cross-compile Python itself for the platform you are targeting - it is not possible from a binary installation of Python (as the .lib etc file for other platforms are not included.) In practice, this means the user of a 32 bit operating system will need to use Visual Studio 2008 to open the PCBuild/PCbuild.sln solution in the Python source tree and build the “x64” configuration of the ‘pythoncore’ project before cross-compiling extensions is possible.

This, however, is only talking about cross-compiling to different Windows versions. It does not discuss (that I saw anywhere) the capability of using gcc for the compiler. You would have to specify the libraries and linker required manually which I can personally say from experience is tedious since build relies on many things, including ones specific to Python.

These dependencies can be tracked down (I did for a while, just for fun :grin:), but it really isn’t worth it when you can just quickly install linux (dual-boot or vm) and then copy your code over (I just used github). Doing it this way is as easy as running almost the exact same command, python3 build and it just works.

Note that I have not tested any of this on the C1 servers yet, but I am assuming it will be fine since my .so file is created and works normally.

Yeah I just learned how to create a VM, discovered Ubuntu and suprinsingly it worked! ( I expected to struggle a bit with all of this)

I took me less time to do this than the first time I tried to compile my module under windows haha


For anyone working on this in the future, I actually did find documentation for how to compile using mingw on Windows for .so files: