'numpy.core._multiarray_umath' not found on embedded Python, but found on console.
See original GitHub issueI can import numpy in the Python console, but cannot import it in an embedded python C++ application that used the same Python version with the same folders. I have only this Python version on my PC. Importing other packages from the application works.
The application sets Py_SetPythonHome() to my Python folder: C:\Users\MyName\AppData\Local\Programs\Python\Python37-32
print(os.file) prints the correct file.
Reproducing code example:
Py_SetProgramName(Py_DecodeLocale(ProgramName,0));
Py_SetPythonHome(Py_DecodeLocale("C:\\Users\\Richard\\AppData\\Local\\Programs\\Python\\Python37-32",0));
Py_Initialize();
PyModuleMain = PyImport_AddModule("__main__");
PyGlobalDict = PyModule_GetDict(PyModuleMain);
const char *Content = "import os; print(os.__file__)\nimport numpy";
PyRun_SimpleString(Content);
import os; print(os.__file__)
import numpy
Error message:
Traceback (most recent call last): File “C:\Users\Richard\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\core_init_.py”, line 40, in <module> from . import multiarray File “C:\Users\Richard\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\core\multiarray.py”, line 12, in <module> from . import overrides File “C:\Users\Richard\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\core\overrides.py”, line 6, in <module> from numpy.core._multiarray_umath import ( ModuleNotFoundError: No module named ‘numpy.core._multiarray_umath’
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “<string>”, line 2, in <module> File “C:\Users\Richard\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy_init_.py”, line 142, in <module> from . import core File “C:\Users\Richard\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\core_init_.py”, line 71, in <module> raise ImportError(msg) ImportError: …
Numpy/Python version information:
1.16.2, 3.7 32 bit Windows
Issue Analytics
- State:
- Created 5 years ago
- Comments:28 (9 by maintainers)
My problem was that I was building the embedded python in Debug mode. In this case python appends a _d to the suffixes when loading files. However, numpy installation did not include those files, so the import would fail.
I too had the same problem. I solved it. My problem statement: (Windows)
-> I had installed Python3.5 at C:\Python35, -> I invoked Python and ran “import numpy” It gave rise to similar problem. << I then realized that the numpy installation was at C:\Users\partha3x\AppData\Roaming\Python\Python37\site-packages\numpy\core\ and NOT from the path I had mentioned at the time of installation. -> So, I modified (re-installed) python at the user profile home directory. -> The home profile directory is C:\Users\partha3x\AppData\Local\Programs\Python\Python37 ->Uninstalled the numpy ->Re-installed numpy With this “import numpy” call succeeded in python
With Visual Studio 2019, I had the same problem. I followed the following steps -> Uninstalled all Pythons that which were installed using VIsual Studio installer. (Not sure if this step helped me) -> In the project properties, in which I was invoking Python (embedded Python) from C++ project, I had set additional Libraries ( Project properties->Linker->General->Additional Library Directories I added C:\Users\partha3x\AppData\Roaming\Python\Python37\site-packages\numpy\core\lib AND -> In the project properties -> Linker->Input->Additional Dependencies , I added npymath.lib.
These fixed the issues.
In Linux, similar to the project properties, the files have to be compiled with additional dependencies with additional directories using make files.
Hope this helps.