[Python] Cython no module named error of own module

Discussão em 'Python' iniciado por Stack, Julho 3, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to compile a standalone executable from a Python project. It consists of several Python files written by me, with one Module being the "main" with the main function as the entry point. For compilation I first use Cython and then GCC. After running the tool-chain, I have an executable that I can run. However, once I move the executable out of the source folder it does not run anymore as I get a ModuleNotFoundError error.

    Traceback (most recent call last):
    File "main.py", line 12, in init main
    ModuleNotFoundError: No module named 'common'


    common here is one of my programmed Python modules. I am on Ubuntu 22.04 with Cython 0.29.37.

    This is my tool-chain:

    python3 -m cython -3 {py_file_string}
    python3 -m cython --embed -3 -o main.c main.py
    gcc -Os -I /usr/include/python3.10 {c_files_string} -lpython3.10 -o {output_name}


    The two strings are the list of Python and C files, respectively. The --embed line is to let GCC know where the main function is. Am I missing something to get a binary that contains all the "code" of the other modules?

    Continue reading...

Compartilhe esta Página