【问题标题】:How to get numpy working properly in Anaconda Python 3.7.6如何让 numpy 在 Anaconda Python 3.7.6 中正常工作
【发布时间】:2020-11-07 18:36:33
【问题描述】:

我正在尝试在 Python 中使用 NumPy。我刚刚安装了 Anaconda Python 3.7,一切似乎都很顺利。但是,我无法导入 numpy(使用 import numpy 行)。当我这样做时,我收到以下错误:

    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.

我可以在 Anaconda Navigator 的 Enviorments 选项卡中看到它,当我尝试在 Eclipse(Pydev) 中使用它时,它会显示在强制内置命令下。我查看了我的 PYTHONPATH,我在 Eclipse 中的环境和我的基本 python 目录(jsmith/anaconda3)都在其中。我尝试导入我在强制内置命令下看到的其他库,这些库工作正常,但 numpy 似乎是唯一有问题的库。调用 pip install numpy 告诉我它已经安装了 1.18.1 版本。我查看了this 堆栈溢出页面,并在 anaconda 提示符下运行了答案中的第一个命令(conda create -n test numpy python=3.7 --no-default-packages)。这行得通,然后我意识到该测试是针对该问题的,并尝试使用 base 代替,并收到此错误:

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

但是调用conda activate base 什么也没做。

【问题讨论】:

  • 尝试pip uninstall numpy,然后是conda install -n base numpy
  • 耶!但是,这确实有效,而不是conda install -n base numpy,我只使用了pip install numpy

标签: python numpy anaconda


【解决方案1】:

正如 @cel 在 cmets 中提到的,使用 pip uninstall numpypip install numpy 卸载并重新安装 numpy 使其工作。

【讨论】:

    【解决方案2】:

    打开 Anaconda 提示: 然后,您必须转到要在 PowerBI 中使用的 Conda 环境。我有一个环境“临时”,所以我首先在“Anaconda Prompt”中激活它:

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

    然后我转到安装文件夹中有“PowerBI”可执行文件的目录:

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

    然后,我从提示启动 PowerBI:

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

    这修复了您遇到的 NumPy 错误。如果您希望任何其他软件包与 PowerBI 一起使用,请将该软件包安装在相应的“Conda 环境”中(在我的情况下是“temp”)。

    确保 Python 主目录 (Anaconda3) 也已添加到 Python 脚本部分的“Power BI Desktop”全局选项中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-08
      • 1970-01-01
      • 2012-09-30
      • 2020-10-06
      • 1970-01-01
      • 2015-05-08
      • 2020-08-27
      • 2018-06-11
      相关资源
      最近更新 更多