3

I'm on Windows using/embedding Python 3.4

I'm trying to embed Python in an existing C++ application. I've pretty much done the job, but I can't get numpy to work.

I have numpy installed via the whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/ Everything works just fine in python.exe, but when I do something like...

PyRun_SimpleString("import numpy\n");

...in the C++ application, I get a traceback which ends with:

\Python\lib\site-packages\numpy\core\__init__.py, line 6, in <module>
from . import multiarray
cannot import 'multiarray'

Well, this made some sense to me. The module multiarray is in ...\Python34\Lib\site-packages\numpy\core\multiarray.pyd I think these .pyd files are basically DLLs, which means an import library is needed.

For example, ...\Python34\lib contains import libraries (I think) for other modules that are contained in pyd files. You have to link against the import lib. in order to import the module in the C++\Python (eg via PyRun_SimpleString("import _elementtree\n"); )

I suppose I need an import library for numpy to link my C++ application against. Anybody know off hand if building numpy from source pops these out? The build process looks tricky, but maybe it's the only options here.

Also, obviously when Python is built, it can't be linked against import libraries for modules that aren't installed yet. In other words, my python.exe wasn't linked against this magic import library I'm looking for, but it can still import numpy, how? Can I recreate this in my application?

sg_man
  • 763
  • 1
  • 6
  • 14

0 Answers0