在 anconda 虚拟虚拟环境中安装 Tensorflow 后 Numpy 版本不兼容

时间:2021-01-05 18:44:07

标签: python numpy tensorflow installation anaconda

我创建了一个虚拟虚拟环境并立即使用以下命令安装了 Tensorflow:

conda install tensorflow

之后,我将 Pycharm 中的环境更改为我创建的环境(python 3.8 版),并尝试运行此代码:

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers


tl = tf.keras.layers.LSTM(6)

我收到以下错误:

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/איתן רוזטי/PycharmProjects/Neural_Network/rnn.py", line 2, in <module>
    import tensorflow as tf
  File "C:\Users\איתן רוזטי\AppData\Local\conda\conda\envs\neural_network\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\איתן רוזטי\AppData\Local\conda\conda\envs\neural_network\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
    from tensorflow.python.eager import context
  File "C:\Users\איתן רוזטי\AppData\Local\conda\conda\envs\neural_network\lib\site-packages\tensorflow\python\eager\context.py", line 29, in <module>
    import numpy as np
  File "C:\Users\איתן רוזטי\AppData\Local\conda\conda\envs\neural_network\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import core
  File "C:\Users\איתן רוזטי\AppData\Local\conda\conda\envs\neural_network\lib\site-packages\numpy\core\__init__.py", line 48, in <module>
    raise ImportError(msg)
ImportError: 

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

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.8 from "C:\Users\איתן רוזטי\AppData\Local\conda\conda\envs\neural_network\python.exe"
  * The NumPy version is: "1.19.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

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

我该怎么做才能解决这个问题并运行代码?

我找到了解决方案: 我卸载了 Numpy(版本 1.19.2)并使用以下命令安装了较低版本(版本 1.18.1):

pip uninstall numpy
pip install numpy==1.18.1

1 个答案:

答案 0 :(得分:0)

好吧,可能您还没有设置系统环境变量路径:

这里是您可以添加的路径。

C:\Users\<username>\AppData\Local\Continuum\Anaconda3\Scripts\
C:\Users\<username>\AppData\Local\Continuum\Anaconda3\Library\
C:\Users\<username>\AppData\Local\Continuum\Anaconda3\Library\bin\
C:\Users\<username>\AppData\Local\Continuum\Anaconda3\Library\mingw-w64\bin\