Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import numpy installed as dependency #126

Closed
liam-clink opened this issue Dec 17, 2024 · 2 comments · Fixed by #140
Closed

Can't import numpy installed as dependency #126

liam-clink opened this issue Dec 17, 2024 · 2 comments · Fixed by #140
Assignees

Comments

@liam-clink
Copy link

On Windows 10, python 3.12

After installing mkl_fft (and mkl_random and mkl_umath), the version of numpy that's installed as a dependency is 1.26.4, and when I try to import it, I get an error. It seems like for some reason numpy is being imported from within its own source directory. When I remove all IntelPython stuff and just install numpy, either the current 2.2.0 version or 1.26.4, it launches just fine, so it's something about how it's installed as a dependency by IntelPython stuff.

PS C:\Users\liam> python
Python 3.12.8 (tags/v3.12.8:2dc476b, Dec  3 2024, 19:30:04) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\numpy\__init__.py:127: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
  from . import _distributor_init
Traceback (most recent call last):
  File "C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\numpy\core\__init__.py", line 24, in <module>
    from . import multiarray
  File "C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\numpy\core\multiarray.py", line 10, in <module>
    from . import overrides
  File "C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\numpy\core\overrides.py", line 8, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\numpy\__init__.py", line 130, in <module>
    from numpy.__config__ import show as show_config
  File "C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\numpy\__config__.py", line 4, in <module>
    from numpy.core._multiarray_umath import (
  File "C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\numpy\core\__init__.py", line 50, in <module>
    raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.12 from "C:\Program Files\Python312\python.exe"
  * The NumPy version is: "1.26.4"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\numpy\__init__.py", line 135, in <module>
    raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python interpreter from there.
@ndgrigorian
Copy link
Collaborator

@liam-clink

If you are still having this problem, can you please show conda list for the environment it happens in?

@ekomarova ekomarova linked a pull request Mar 24, 2025 that will close this issue
@ekomarova
Copy link
Collaborator

I assume you're using venv and pip, and that's the reason for the issue. The libraries needed to load numpy, mkl_* packages for wheels are in "Library\bin", which is not the default path, the default path is "Lib\site-packages". As workaround for current releases, you can do the following:

import os, site
path_to_env = site.getsitepackages()[0]
path_to_libs = os.path.join(path_to_env, "Library", "bin")
os.add_dll_directory(path_to_libs)
import numpy

This adds "Library\bin" to the library search path, which will allow you to load numpy and mkl_* correctly.

@ekomarova ekomarova self-assigned this Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants