I am embedding python into my C/C++ code. I need to set the module search path at runtime for the platform I am on before python is initialised. I only know how to get the module path from python, how can I get this without python?
Currently, I use Py_GetPath and Py_SetPath to indicate this using a hard coded path, i.e. '/usr/local/lib/python2.7/site-packages' for 'requests'.
Search paths are used by python when you import modules. To locate a module within python you can;
>>> import pkgutil
>>> package = pkgutil.get_loader("requests")
>>> package.filename
So I would also have to set the search path for pkgutil as well.
Aucun commentaire:
Enregistrer un commentaire