Skip to content
Advertisement

Running numpy using anaconda and VS Code

I am trying to get VScode to work with anaconda but having issues with numpy. I have managed to get VScode to use the right python environment From VScode (ctrl+shift+P, type Python:Select Interpreter and select the appropriate option).

However, when I type “import numpy” in to my script, I get the following error message:

C:ProgramDataAnaconda3envssandpitlibsite-packagesnumpy__init__.py:140: 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:ProgramDataAnaconda3envssandpitlibsite-packagesnumpycore__init__.py", line 24, in <module>
    from . import multiarray
  File "C:ProgramDataAnaconda3envssandpitlibsite-packagesnumpycoremultiarray.py", line 14, in <module>
    from . import overrides
  File "C:ProgramDataAnaconda3envssandpitlibsite-packagesnumpycoreoverrides.py", line 7, 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[NAME]Documentspythonsandpithello.py", line 2, in <module>
    import numpy
  File "C:ProgramDataAnaconda3envssandpitlibsite-packagesnumpy__init__.py", line 142, in <module>
    from . import core
  File "C:ProgramDataAnaconda3envssandpitlibsite-packagesnumpycore__init__.py", line 54, in <module>
    raise ImportError(msg)
ImportError: 

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

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.8 from "C:ProgramDataAnaconda3envssandpitpython.exe",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.18.1" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

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

I have successfully called the ‘import numpy’ command from the anaconda command prompt so it seems the issue is just with VS-Code?

I have also tried to reinstall numpy from the environment with the following command conda install numpy --force-reinstall but this has no effect?

Advertisement

Answer

Try launching VS Code from your activated conda environment. Errors like this typically come up if you managed to run code before your shell had a chance to do a conda environment activation.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement