MasterMind
MasterMind

Reputation: 389

numpy import fails when Python is embedded in C++

I've got a problem when accessing numpy with Python 2.7 embedded into my C++ application (32-bits) and statically linked. Under my application executable, I've placed python27.dll along with the Python27 directory with all needed DLLs. I've also installed Python 2.7 and numpy (all 32-bits) in a separate folder (C:\Python27). When I run my application and try to import numpy, here is the error I receive:

Traceback (most recent call last):
File "pytest", line 1, in <module>
    File "C:\Python27\lib\site-packages\numpy\__init__.py", line 137, in <module>
    import add_newdocs
    File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
    File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 4, in <module>
    from type_check import *
    File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 8, in <module>
    import numpy.core.numeric as _nx
    File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 5, in <module>
    import multiarray
ImportError: DLL load failed: The specified module could not be found.

When I delete python27.dll from my application folder, then I am able to import numpy. I cannot ask the client to manually delete python27.dll when he wants to import any Python third-party library... anyone has ideas on how I can fix that? What's up with this multiarray module?

Upvotes: 1

Views: 2140

Answers (1)

MasterMind
MasterMind

Reputation: 389

Ok, problem resolved. The python27.dll file under the embedded application folder must be the same as the Python 2.7 release. Verify dates to make sure they are the same. If they are not the same, you may encounter various problems.

My Application Folder
    myApp.exe
    python27.dll  <-- must be the same as Python installed on your machine
    Python27 Folder
        DLL
        Libs

Upvotes: 2

Related Questions