【问题标题】:Can't import numpy from pycharm无法从 pycharm 导入 numpy
【发布时间】:2020-01-08 11:09:19
【问题描述】:

我有 Anaconda3。当我使用 Pycharm 的解释器或直接从文件夹导入 numpy 时,出现以下错误:

ImportError                               Traceback (most recent call last)
~\Anaconda\lib\site-packages\numpy\core\__init__.py in <module>
     16 try:
---> 17     from . import multiarray
     18 except ImportError as exc:

~\Anaconda\lib\site-packages\numpy\core\multiarray.py in <module>
     13
---> 14 from . import overrides
     15 from . import _multiarray_umath

~\Anaconda\lib\site-packages\numpy\core\overrides.py in <module>
      6
----> 7 from numpy.core._multiarray_umath import (
      8     add_docstring, implement_array_function, _get_implementing_args)

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-d4cdadb62aa7> in <module>
----> 1 import numpy

~\Anaconda\lib\site-packages\numpy\__init__.py in <module>
    140     from . import _distributor_init
    141
--> 142     from . import core
    143     from .core import *
    144     from . import compat

~\Anaconda\lib\site-packages\numpy\core\__init__.py in <module>
     45 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
     46         __version__, exc)
---> 47     raise ImportError(msg)
     48 finally:
     49     for envkey in env_added:

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\noamw\Anaconda\python.exe",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.17.4" 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.

但是,当我在激活我的环境后从 ipython 使用它时,使用 conda,它工作得很好。无法创建这样的 Pycharm 项目,真是令人沮丧。 非常感谢任何帮助 谢谢

【问题讨论】:

  • 我遇到了小问题

标签: python python-3.x numpy anaconda


【解决方案1】:

将您的环境设置为 PyCharm 的解释器应该可以工作。转到Preferences --> Project --> Project Interpreter。在下拉菜单中选择您的 conda 环境。将其设置为:~/Anaconda3/envs/myenvname/bin/python

【讨论】:

  • 我已经这样做了,不幸的是这并没有解决问题。它可以运行python,只是不导入numpy或sqlite
【解决方案2】:

令人遗憾的是,Pycharm 没有调查这个问题,也没有提出解决方案。

我发现的大多数解决方案都建议删除 numpy 并使用 pip install numpy 重新安装它,这基本上违背了拥有 conda 环境并获得 conda 修订等好处的目的;更不用说在同一环境中同时使用 pip 和 conda 的坏习惯了。

在 Pycharm 解决此问题之前,您可以通过以下方式解决此问题:

  1. 在命令提示符下激活您的环境。
  2. 使用set 命令打印所有环境变量。
  3. 复制PATH 环境变量。

  1. 将其添加到运行/调试配置的环境变量中。

【讨论】:

  • 这是唯一对我有用的解决方案。应该得到更高的评价。
猜你喜欢
  • 1970-01-01
  • 2020-05-08
  • 1970-01-01
  • 2016-06-08
  • 2020-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-31
相关资源
最近更新 更多