You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'numpy.core._multiarray_umath' not found on embedded Python, but found on console. #13051
I 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
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
from . import multiarray
File "C:\Users\Richard\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\core\multiarray.py", line 12, in
from . import overrides
File "C:\Users\Richard\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\core\overrides.py", line 6, in
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 "", line 2, in
File "C:\Users\Richard\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy_init_.py", line 142, in
from . import core
File "C:\Users\Richard\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\core_init_.py", line 71, in
raise ImportError(msg)
ImportError:
...
This is probably a duplicate of several other issues but I think the embedded Python is new. See if the discussion at #12977 is helpful. How did you install NumPy? Are you working with Anaconda?
I have installed with pip install numpy. No Anaconda and no other Pythons on the system.
I get the error message with the Python debug DLL. When I use the release DLL, the line "import numpy" immediately causes a crash in the PyRun_SimpleString() call.
I have also added ...Lib\site-packages\numpy\.libs to the PATH as suggested in the other thread, but to no avail. That folder contains a libopenblas.JKAMQ5EVHIVCPXP2XZJB2RQPIN47S32M.gfortran-win32.dll.
Yes, importing lxml works with my app. And copying the DLL from .libs to core did not help. I've also changed the Python version to 3.6, but the problem remains. BTW, the pyd file in core is named "_multiarray_umath.cp36-win32.pyd".
The Zip contains a folder "ZorroBeta". Unzip it anywhere on a Windows PC. It contains a lot of other stuff that won't matter here. Install Python 3.6. and Numpy on that PC. In the ZorroBeta folder, edit Zorro.ini and enter the path to Python 3.6 in double quotes next to "PythonPath". Then start the program Zorro.exe. It will open a panel. With the scrollbox marked "Script", select "NumPy". Then click "Test". Now go to the subfolder "Log". It contains two files PyError.txt and PyOut.txt. PyError.txt should be empty when the Numpy import worked. Otherwise it contains the error message.
Alternatively the problem can be already checked with the simple main() example in the Python manual.
I have the same problem. I have an application with embedded python. When trying to load numpy, it fails with the same error. And it works fine from the command line python.
I found that it also fails to load pytorch, with a similar error. The common issue i found is that the failed files have an extension made by concatenating the python version and the platform (e.g. cp37-win_amd64).
Since the PATH are fine, i think the problem is that the embedded python does not know how to build that extension. I'm trying to dig this out, but to no avail so far. But it seems that the problem is in Python rather than numpy (or pytorch).
In numpy, the failed command is:
from . import _multiarray_umath
and the corresponding file is:
C:\Program Files\Python37\Lib\site-packages\numpy\core\ _multiarray_umath.cp37-win_amd64.pyd
In pytorch, the failed command is:
from torch._C import *
and the corresponding file is:
C:\Program Files\Python37\Lib\site-packages\torch\ _C.cp37-win_amd64.pyd
Closing. This issue started about trying to use a release version of NumPy on a debug version of windows python, and transitioned to talking about reimporting after calling Py_Finalize();, which is not supported.
Please open a new issue if there is something I missed.
Well, I fear it has absolutely nothing to do with debug or release versions. But this is a quite old thread and my software was delivered long ago. So for me the issue is closed.
I just had to write in the documentation that NumPy does not clean exit, so for starting it twice the user had to close and restart the whole application, or use a different vector library. Fortunately, only Numpy had this problem. I never encountered it with other Python math libraries.
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.
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'm also stuck with this problem. Could you help me? What do you mean by "I was building the embedded python in Debug mode". How can I change that? I tried to switch to release mode and the include lines just turn red for some reason. They wont let me compile
Have u checked if it's the release or debug problem? I've met the same situation as you did, using python 3.7.4 and numpy 1.17 (installed through pip) on windows. In C++ program, check sys.path of embedded python to see if it is looking for a "_d" suffix. And changing from debug mode to release mode solved my problem.
I switched to release mode. Now Py_initialize throws "Could not find platform independent libraries <prefix"
Activity
charris commentedon Feb 27, 2019
This is probably a duplicate of several other issues but I think the embedded Python is new. See if the discussion at #12977 is helpful. How did you install NumPy? Are you working with Anaconda?
RichardEdye commentedon Feb 27, 2019
I have installed with pip install numpy. No Anaconda and no other Pythons on the system.
I get the error message with the Python debug DLL. When I use the release DLL, the line "import numpy" immediately causes a crash in the PyRun_SimpleString() call.
RichardEdye commentedon Feb 27, 2019
I have also added ...Lib\site-packages\numpy\.libs to the PATH as suggested in the other thread, but to no avail. That folder contains a libopenblas.JKAMQ5EVHIVCPXP2XZJB2RQPIN47S32M.gfortran-win32.dll.
mattip commentedon Mar 6, 2019
A couple of things might be happening.
'.libtocorenext to the_multiarray_umath.pydfile.Can you use other c-extension modules, for instance lxml?
RichardEdye commentedon Mar 6, 2019
Yes, importing lxml works with my app. And copying the DLL from .libs to core did not help. I've also changed the Python version to 3.6, but the problem remains. BTW, the pyd file in core is named "_multiarray_umath.cp36-win32.pyd".
If it helps, I can upload my app for testing.
mattip commentedon Mar 6, 2019
a link to the app repo or a pastebin with the code might be helpful, but I don't really use Windows these days so it might take a while to look at.
RichardEdye commentedon Mar 6, 2019
Ok, I've uploaded it here:
https://opserver.de/down/NumPyTest.zip
The Zip contains a folder "ZorroBeta". Unzip it anywhere on a Windows PC. It contains a lot of other stuff that won't matter here. Install Python 3.6. and Numpy on that PC. In the ZorroBeta folder, edit Zorro.ini and enter the path to Python 3.6 in double quotes next to "PythonPath". Then start the program Zorro.exe. It will open a panel. With the scrollbox marked "Script", select "NumPy". Then click "Test". Now go to the subfolder "Log". It contains two files PyError.txt and PyOut.txt. PyError.txt should be empty when the Numpy import worked. Otherwise it contains the error message.
Alternatively the problem can be already checked with the simple main() example in the Python manual.
elikosan commentedon Apr 24, 2019
I have the same problem. I have an application with embedded python. When trying to load numpy, it fails with the same error. And it works fine from the command line python.
I found that it also fails to load pytorch, with a similar error. The common issue i found is that the failed files have an extension made by concatenating the python version and the platform (e.g. cp37-win_amd64).
Since the PATH are fine, i think the problem is that the embedded python does not know how to build that extension. I'm trying to dig this out, but to no avail so far. But it seems that the problem is in Python rather than numpy (or pytorch).
In numpy, the failed command is:
from . import _multiarray_umath
and the corresponding file is:
C:\Program Files\Python37\Lib\site-packages\numpy\core\ _multiarray_umath.cp37-win_amd64.pyd
In pytorch, the failed command is:
from torch._C import *
and the corresponding file is:
C:\Program Files\Python37\Lib\site-packages\torch\ _C.cp37-win_amd64.pyd
mattip commentedon Apr 25, 2019
Is there a missing
\betweencoreand_multiarray_umath? Thepydfile should sit in thecoredirectory.elikosan commentedon Apr 25, 2019
Yes. The github web editor seems to eat the backslash when rendering a backslash followed by an underscore. I added a space.
mattip commentedon May 1, 2019
Are you mixing python 3.6 and python 3.7?
19 remaining items
mattip commentedon Dec 3, 2019
Closing. This issue started about trying to use a release version of NumPy on a debug version of windows python, and transitioned to talking about reimporting after calling
Py_Finalize();, which is not supported.Please open a new issue if there is something I missed.
RichardEdye commentedon Dec 3, 2019
Well, I fear it has absolutely nothing to do with debug or release versions. But this is a quite old thread and my software was delivered long ago. So for me the issue is closed.
I just had to write in the documentation that NumPy does not clean exit, so for starting it twice the user had to close and restart the whole application, or use a different vector library. Fortunately, only Numpy had this problem. I never encountered it with other Python math libraries.
alkalinin commentedon Feb 29, 2020
This is a problem of the 'pyd' naming convention, see python issue 36716.
CommandLine Python:
C++ Embedded Python:
spartha77 commentedon Apr 8, 2020
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.
MyFirstGitEver commentedon Jan 31, 2024
I'm also stuck with this problem. Could you help me? What do you mean by "I was building the embedded python in Debug mode". How can I change that? I tried to switch to release mode and the include lines just turn red for some reason. They wont let me compile
MyFirstGitEver commentedon Jan 31, 2024
I switched to release mode. Now Py_initialize throws "Could not find platform independent libraries <prefix"
RichardEdye commentedon Feb 1, 2024