Erhode
Erhode

Reputation: 172

Unable to load pyd module generated with MSYS2 MinGW 32bit

I have two simple files: main.py and config_cowsay.py

main.py

import cowsay
import config_cowsay

char = config_cowsay.choose_character()
print(char)
print(cowsay.get_output_string(char, "Raptors are evil"))

config_cowsay.py

from random import *

def choose_character():
    n = randint(1, 3)
    switch = {
        1: "trex",
        2: "cow",
        3: "stegosaurus",
    }
    return switch.get(n, "daemon")

If I run main.py, the program executes correctly. Now I need to transform config_cowsay into a pyd file and still be able to call it from main.py. I used MSYS MinGW 32-bit with a makefile to do it (linking the makefile doesn't add anything to the problem resolution I think but I can do it if required). Executing my Makefile from MSYS MinGW 32-bit terminal generates me a folder with the previous main.py and a config_cowsay.pyd next to it. It also generates a main.exe as a one file executable in another folder.

 root  
   |-src
      |-main.py
      |-config_cowsay.py
   |-test_cowsay
      |-main.py
      |-config_cowsay.pyd 
   |-dist
      |-main.exe

So now, if I run the exe from a powershell terminal, the program runs perfectly. If I run the main.py file next to the config_cowsay.pyd using the MSYS MinGW 32-bit terminal, the main.py script executes perfectly using the pyd module and without having to change anything in the main.py code. But if I try to run main.py with my powershell terminal using python main.py, I get an error telling me that the module config_cowsay doesn't exist.

module not found

I already tried everything I could find on this subject. Adding the pyd file to the sys.path variable, editing PYTHONPATH environment variable, moving the pyd dll to site-package or DLLs python folder, renaming config_cowsay.pyd to config_cowsay_p.pyd etc...

I made sure that the environment of MSYS is the same as my computer, the same python version 3.8.9 32 bit with the same modules installed etc... So it shouldn't be a python version issue. On top of that, running the output main.exe from my powershell terminal works, meaning my computer environment should be compatible with the MSYS one I used to generate the pyd dll.

Let me know if you need more details. Thanks for your help!

Upvotes: 0

Views: 248

Answers (1)

Erhode
Erhode

Reputation: 172

I got it to work by getting read of MSYS environment and using directly my computer python environment. I installed python globally on the computer and used a setup file (https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html) instead of a makefile.

Upvotes: 1

Related Questions