问题描述
我在Windows Python 3.5 Anaconda环境中安装了TensorFlow验证成功(带有警告)
I installed TensorFlow on my Windows Python 3.5 Anaconda environmentThe validation was successful (with a warning)
(tensorflow) C:\>python
Python 3.5.3 |英特尔公司| (默认值,2017年4月27日,17:03:30)在Win32上的[MSC v.1900 64位(AMD64)]
Python 3.5.3 |Intel Corporation| (default, Apr 27 2017, 17:03:30) [MSC v.1900 64 bit (AMD64)] on win32
键入帮助",版权",信用"或许可证"以获取更多信息.英特尔公司为您提供了Python的英特尔(R)发行版.请查看: https://software.intel.com/zh-cn/python-distribution
Type "help", "copyright", "credits" or "license" for more information.Intel(R) Distribution for Python is brought to you by Intel Corporation.Please check out: https://software.intel.com/en-us/python-distribution
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2017-10-04 11:06:13.569696:WC:\ tf_jenkins \ home \ workspace \ rel-win \ M \ windows \ PY \ 35 \ tensorflow \ core \ platform \ cpu_feature_guard.cc:45] TensorFlow库尚未编译为使用AVX指令,但是这些指令在您的计算机上可用,并且可以加快CPU计算速度.
2017-10-04 11:06:13.569696: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
>>> print(sess.run(hello))
b'你好,TensorFlow!'
b'Hello, TensorFlow!'
但是,当我尝试将其导入到我的python代码中
However, when I attempt to import it into my python code
from __future__ import print_function, division
import numpy as np
import os
import matplotlib
import tensorflow as tf
我收到此错误
这是我的C驱动器上的tensorflow软件包的位置
This is the location of the tensorflow package on my C drive
C:\Users\myname\Anaconda2\envs\tensorflow\Lib\site-packages\tensorflow
当我转到Anaconda Navigator时,似乎必须选择root,Python35或Tensorflow.看起来Tensorflow环境包含Python35.
When I go to Anaconda Navigator, it seems I have to choose either root, Python35, or Tensorflow. It looks like the Tensorflow environment includes Python35.
Anaconda Navigator启动器必须最近重新安装,可能是由于Tensorflow安装所致.也许除了导航器之外,还有其他方法可以将环境设置为Anaconda/Spyder IDE中的Tensorflow
Anaconda Navigator launcher had to be reinstalled recently, possibly due to the Tensorflow installation. Maybe if there were another way to set the environment to Tensorflow within Anaconda /Spyder IDE other than the Navigator it might help
安装Tensorflow的方法
Method of installing tensorflow
conda create --name tensorflow python=3.5;
pip install --ignore-installed --upgrade tensorflow
我确实尝试过:某些博客建议卸载并重新安装protobuf
I did try:uninstalling and reinstalling protobuf, as suggesed by some blogs
我看到另一个SO用户在3月问了同一问题,没有收到任何回复
I see another SO user asked the same question in March, received no reply
推荐答案
Python 3.5环境无法导入Tensorflow的原因是Anaconda不在同一环境中存储tensorflow软件包.
The reason Python 3.5 environment is unable to import Tensorflow is that Anaconda does not store the tensorflow package in the same environment.
一种解决方案是使用自己的Spyder在Anaconda中为TensorFlow创建一个新的单独环境
One solution is to create a new separate environment in Anaconda dedicated to TensorFlow with its own Spyder
conda create -n newenvt anaconda python=3.5
activate newenvt
然后将tensorflow安装到 newenvt
and then install tensorflow into newenvt
我发现这本入门书很有帮助
这篇关于Tensorflow导入错误:没有名为'tensorflow'的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!