简体   繁体   English

在Python 3.6中安装和导入Tensorflow时遇到问题

[英]Having trouble installing and importing tensorflow in Python 3.6

I am using windows, Python 3.6.7, and conda 4.5.12 我正在使用Windows,Python 3.6.7和conda 4.5.12

Here is what I've done so far: 到目前为止,这是我所做的:

-since tensorflow only works on Python 3.4, 3.5, and 3.6 I created an environment in anaconda prompt conda create -n py36 python=3.6 anaconda -因为tensorflow仅适用于Python 3.4、3.5和3.6,所以我在anaconda提示符下创建了一个环境conda create -n py36 python=3.6 anaconda

  • activated the environment conda activate py36 激活环境conda activate py36

  • attempted to install tensorflow using anaconda but it failed: 试图使用anaconda安装tensorflow但失败了:

    (py36) C:\\Users\\jim>conda install -c conda-forge tensorflow (py36) C:\\Users\\jim>conda install -c conda-forge tensorflow

Solving environment: failed 解决环境:失败

CondaUpgradeError: This environment has previously been operated on by a conda version that's newer than the conda currently being used. CondaUpgradeError:此环境以前已通过比当前使用的conda更新的conda版本进行操作。 A newer version of conda is required. 需要较新版本的conda。 target environment location: C:\\Users\\jim\\Anaconda3\\envs\\py36 current conda version: 4.5.12 minimum conda version: 4.6 目标环境位置:C:\\ Users \\ jim \\ Anaconda3 \\ envs \\ py36当前conda版本:4.5.12最低conda版本:4.6

  • so I just installed it with pip and it worked: 所以我只是用pip安装了它,它起作用了:

    (py36) C:\\Users\\jim>pip install tensorflow (py36)C:\\ Users \\ jim> pip安装张量流

  • this screenshot confirms that tensorflow is installed 此屏幕快照确认已安装tensorflow

  • went into anaconda navigator, switched to py36, and opened up a jupyter notebook (doesn't work in Spyder either), and got this: 进入anaconda导航器,切换到py36,并打开了一个jupyter笔记本(在Spyder中也不起作用),并得到了以下信息:

    import tensorflow as tf


ModuleNotFoundError Traceback (most recent call last) ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' ModuleNotFoundError跟踪(最近一次调用最近)ModuleNotFoundError:没有名为“ numpy.core._multiarray_umath”的模块


ImportError Traceback (most recent call last) ImportError: numpy.core.multiarray failed to import ImportError跟踪(最近一次调用最近)ImportError:numpy.core.multiarray导入失败

The above exception was the direct cause of the following exception: 上面的异常是以下异常的直接原因:

SystemError Traceback (most recent call last) ~\\Anaconda3\\envs\\py36\\lib\\importlib_bootstrap.py in _find_and_load(name, import_) SystemError追溯(最近一次通话最后一次)〜\\ Anaconda3 \\ envs \\ py36 \\ lib \\ importlib_bootstrap.py in _find_and_load(name,import_)

SystemError: returned a result with an error set SystemError:返回了带有错误集的结果


ImportError Traceback (most recent call last) ImportError: numpy.core._multiarray_umath failed to import ImportError跟踪(最近一次通话最近)ImportError:numpy.core._multiarray_umath导入失败


ImportError Traceback (most recent call last) ImportError: numpy.core.umath failed to import ImportError跟踪(最近一次调用最近)ImportError:numpy.core.umath导入失败

and then the kernel dies and it resets. 然后内核死亡,然后重置。

Any thoughts on what might be wrong? 有什么想法可能有问题吗?

You can try these steps: 您可以尝试以下步骤:

    1.conda create --name tf_env python=3.6

    2. conda activate tf_env

    3. conda install -c conda-forge tensorflow=1.12.0

    4. Try importing tensorflow 

    5. conda deactivate

create tensorflow environment than active it: 创建tensorflow环境而不是激活它:

conda create -n tensorflow_env tensorflow
    conda activate tensorflow_env

In my case I was having trouble importing keras after running conda install keras 以我为例,我无法汇入keras运行后conda install keras

It worked when I upgraded my numpy installation. 当我升级numpy安装时,它起作用了。 This site suggests numpy version 1.16 will work better, and that pip install may be needed (vs conda install ): 该站点建议numpy 1.16版会更好,并且可能需要pip install (与conda install ):

pip install numpy==1.16

Also, after installing conda install keras , some of my colleagues had a different error; 另外,在安装conda install keras ,我的一些同事有一个不同的错误; an error like "Could not find module named tensorflow ". 诸如“找不到名为tensorflow模块”之类的错误。 We fixed this by installing tensorflow : pip install tensorflow 我们通过安装tensorflow解决此tensorflowpip install tensorflow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM