【问题标题】:After installing Jupyter Notebook NumPy and TensorFlow are not working安装 Jupyter Notebook NumPy 和 TensorFlow 后无法正常工作
【发布时间】:2019-08-09 15:54:30
【问题描述】:

我今天使用 Jupyter Notebook 做一些学习,发现我无法导入 Tensorflow 或 Keras。这很奇怪,因为直到昨天它工作正常。不管怎样,我上网查了一下,有人建议我使用conda install jupyter notebook 再次安装 Jupyter。我正是这样做的,现在我什至无法导入 Tensorflow 或 NumPy。更不用说每当我尝试打开也不起作用的 Jupyter 时。我看到命令提示符短暂闪烁,然后没有任何反应。

当我尝试导入其中一个时,我收到此错误:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
~\Anaconda3\lib\site-packages\numpy\core\__init__.py in <module>
     39 try:
---> 40     from . import multiarray
     41 except ImportError as exc:

~\Anaconda3\lib\site-packages\numpy\core\multiarray.py in <module>
     11
---> 12 from . import overrides
     13 from . import _multiarray_umath

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

ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-0aa0b027fcb6> in <module>
----> 1 import numpy as np

~\Anaconda3\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

~\Anaconda3\lib\site-packages\numpy\core\__init__.py in <module>
     69 Original error was: %s
     70 """ % (sys.executable, exc)
---> 71     raise ImportError(msg)
     72 finally:
     73     for envkey in env_added:

ImportError:

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

Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
  your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
  1. Check that you are using the Python you expect (you're using 
C:\Users\seant\Anaconda3\python.exe),
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy versions 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

     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: No module named 'numpy.core._multiarray_umath'

我尝试重新安装 NumPy,但这并没有解决问题。我通过安装 Anaconda 安装了 Python 和 NumPy,我的操作系统是 Windows 10。我的路径变量看起来也很正常,到目前为止一切正常。有谁知道我该如何解决这个问题?

【问题讨论】:

    标签: python anaconda jupyter-notebook importerror


    【解决方案1】:

    转到您的终端并找到您安装了 Numpy 和其他模块的环境。如果你使用 virtualenvwrapper,你可以运行: lsvirtualenv 将显示您拥有的虚拟环境列表。

    然后输入workon virtualenv1(替换为显示的虚拟环境的名称)并检查您安装的模块,例如在选择虚拟环境后,您可以输入 python 并进入外壳。然后您可以执行import numpy 等检查您要查找的模块是否存在于该 virtualenv 中。当您找到它们时,您可以退出 shell 并执行 pip install jupyter 以在虚拟环境中安装带有您需要的模块的 jupyter notebooks。为避免将来遇到此类问题,您应该确保在您的机器中维护虚拟环境,其中包含您有兴趣按照虚拟环境使用的模块。 Virtualenvwrapper 是一个很棒的工具,它可以抽象出使用虚拟环境时发现的大多数常见缺陷。有关管理和创建虚拟环境的更多信息can be found here

    【讨论】:

      【解决方案2】:

      在我的例子中,我只花了大约一个小时卸载所有与 Python 相关的东西(Python、Anaconda 等)并再次从头开始完全安装所有东西。这有点痛苦,但我不知道还能做什么,而不必深入研究这个问题。

      【讨论】:

        猜你喜欢
        • 2020-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-13
        • 1970-01-01
        相关资源
        最近更新 更多