I am , as of now, simply trying to get this example given in the python docs for embedding a python module in C to work. My problem is I can’t figure out where to put the python script. My ultimate goal is to have a full python package (folder with a __init__.py and various modules) to be loadable in C by executing PyImport_Import(...). But for now, please just let me know where to put the script shown (filename, path, etc) so that the C program given will run.
EDIT
I should point out what I’ve tried. I have tried putting a multiply.py file in the local directory, as well as putting it in a subdirectory called multiply in an __init__.py file. In all of these cases, I get ImportError: No module named multiply
I think it should be in the same directory or in
sys.pathas it loads a module by name, this should work:Update: if I add the current directory explicitly to
sys.pathit works:And this prints:
Update: I’ve asked a relevant question and it seems that if you just add
PySys_SetArgvinstead it works:The reason is mentioned here:
And this is the question you can check the answers there too:
Why does PyImport_Import fail to load a module from the current directory?