I'm trying to embed python in to my application and have got stuck pretty early on.
I am embedding python into my C++ application and using the code found at this tutorial: http://docs.python.org/2/extending/embedding.html#pure-embedding
My application matches entirely and compiles successfully no errors. However on running the application pModule = PyImport_Import(pName);
line fails returning 0 meaning I get error output from PyErr_Print() of
Failed to load "C:\Users\workspace\dpllib\pyscript.py"
ImportError: Import by filename is not supported.
The application is being called with the commands C:\Users\workspace\ndnlib\pyscript.py multiply 50 150
I can't be sure, but I'm thinking that since pName is set to argv[1] and you're using the full path to call the script, then argv[1] is the full path. This means the code would try to import "C:\Users\workspace\dpllib\pyscript.py", which python can't (it can only import "pyscript").
Try running the script by just typing "pyscript.py" from within the directory and see if the error changes to 'Failed to load "pyscript.py"'. If it does, then you have to fix it so it doesn't just import argv[1] and modifies the string to get a module name instead of a file name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With