I am running python scripts from within my C++ application using boost::python
. I get the error: ModuleNotFoundError: No module named 'math'
. Some builtin modules work, but some don't. For example, import sys
works.
I verified that I have a normal python installation and the modules are all imported correctly when I run python from command line.
I printed sys.path
, sys.executable
, sys.version
, sys.builtin_module_names
in both the embedded version and the command line version and there is only one difference - the builtin modules list is shorter when run from inside my C++ executable, with some modules are missing.
What am I missing?
FYI, I am running into the exact same problem.
I am running on RHEL 7 and am building a shared library that is part of a complex system. Of the following 4 calls, only calendar fails (returns null):
PyObject* t1 = PyImport_ImportModule("calendar");
PyObject* t2 = PyImport_ImportModule("itertools");
PyObject* t3 = PyImport_ImportModule("appdirs");
PyObject* t4 = PyImport_ImportModule("cython");
After trying a whole bunch of different modules/packages, it appears it works for built in packages like sys and itertools, AND it works for modules in site-packages (that is simple.py files in site-packages), but not when you have a full fledged package...a directory with an init .py file
If you put the call to PyImport_ImportModule in a try/catch block:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.