Tony Baston
Tony Baston

Reputation: 691

How to get numpy working properly in Anaconda Python 3.7.6

I am trying to use NumPy in Python. I have just installed Anaconda Python 3.7, and that all seemed to go smoothly. However, I cannot import numpy(using the line import numpy). When I do, I get the following error:

    C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__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:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
    from . import multiarray
  File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
    from . import overrides
  File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import core
  File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\__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.7 from "C:\Users\jsmith\anaconda3\python.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: The specified module could not be found.

I can see it in the Enviorments tab of Anaconda Navigator, and when I try to use it in Eclipse(Pydev) it shows up under forced builtins. I took a look at my PYTHONPATH, and both my enviorment in Eclipse and my base python directory (jsmith/anaconda3) are in it. I have tried importing other libraries I see under forced builtins,and those work fine, yet numpy seems to be the only one with issues. Calling pip install numpy tells me it is already installed with version 1.18.1. I looked at this stack overflow page, and ran the first command in the answer(conda create -n test numpy python=3.7 --no-default-packages) in anaconda prompt. This worked, and then I realized the test was specific to the question, and tried base instead, and got this error:

CondaValueError: The target prefix is the base prefix. Aborting.

However calling conda activate base did nothing.

Upvotes: 11

Views: 35435

Answers (3)

I better way is to

import os
import sys
os.path.dirname(sys.executable)

This will give you the path to your environment. Put the path into the settings for python

Upvotes: 0

Ashish Jain
Ashish Jain

Reputation: 467

Open the Anaconda Prompt: Then, you have to go to the Conda Environment that you want to use in PowerBI. Am having an environment 'temp', so I activate it first in the 'Anaconda Prompt':

(base) C:\Users\ashish>conda activate temp

Then I go to the directory having the "PowerBI" executable file in the installation folder:

(temp) C:\Users\ashish>cd "C:\Program Files\Microsoft Power BI Desktop\bin"

Then, I launch PowerBI from the Prompt:

(temp) C:\Program Files\Microsoft Power BI Desktop\bin>PBIDesktop.exe

This fixes the NumPy error you are getting. If you want any other package to use with PowerBI, install that package in the respective "Conda Environment" (in my case it is "temp").

Make sure the Python home directory (Anaconda3) has been added to the 'Power BI Desktop' global options in the Python scripting section too.

Upvotes: -1

Tony Baston
Tony Baston

Reputation: 691

As mentioned in the comments by @cel uninstalling and reinstalling numpy using pip uninstall numpy and pip install numpy made it work.

Upvotes: 22

Related Questions