Bilel Mnasser
Bilel Mnasser

Reputation: 21

How can i specify to python cffi , to add my import modules into the generated DLL?

i have a simple Python code to generate a Dll Using CFFI :

import cffi 
 ffibuilder = cffi.FFI()

ffibuilder.embedding_api("""
  int Predict();
""")

ffibuilder.set_source("landmark_Library", "")



ffibuilder.embedding_init_code("""
from landmark_Library import ffi
import argparse
from parse_config import ConfigParser
import deepmvlm
from utils3d import Utils3D
@ffi.def_extern()
def Predict():
    return 2
""")

ffibuilder.compile(target="landmark_Library.*", verbose=True)

i got this error when calling the dll function : if i add the directory with sys.path.insert(0, "."), it will only work only in my computer , if i change computer the dll will stop working and i get this error.

the dll function is called but he can't find the imports

Upvotes: 1

Views: 663

Answers (1)

Armin Rigo
Armin Rigo

Reputation: 12990

The error should be self-descriptive: you are doing from parse_config import ... but there is no module parse_config found.

If you know where the module really is (e.g. in some parse_config.py file or parse_config\\__init__.py file), then make sure that location is in sys.path. The current value of sys.path is printed as part of the error message. You can check if it is indeed missing, and if so, you can add it. In particular, it seems that the current directory . is not in sys.path in your case, so maybe you need to add that (write sys.path.insert(0, ".") on a line before from parse_config import ...). Replace "." with the real path if it is somewhere else.

Upvotes: 0

Related Questions