本文介绍了Tensorflow 导入错误:没有名为“tensorflow"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows Python 3.5 Anaconda 环境中安装了 TensorFlow验证成功(有警告)

(tensorflow) C:>python

Python 3.5.3 |英特尔公司|(默认,2017 年 4 月 27 日,17:03:30)[MSC v.1900 64 位 (AMD64)] 在 win32 上

输入help"、copyright"、credits"或license"以获取更多信息.英特尔(R) Python 发行版由英特尔公司提供.请查看:https://software.intel.com/en-us/python-distribution

>>>将张量流导入为 tf>>>hello = tf.constant('你好,TensorFlow!')>>>sess = tf.Session()

2017-10-04 11:06:13.569696: WC:f_jenkinshomeworkspaceel-winMwindowsPY35ensorflowcoreplatformcpu_feature_guard.cc:45] TensorFlow 库未编译为使用 AVX 指令,但这些指令可在您的机器上使用,并且可以加快 CPU 计算.

>>>打印(sess.run(你好))

b'你好,TensorFlow!'

但是,当我尝试将其导入我的 python 代码时

from __future__ import print_function, Division将 numpy 导入为 np导入操作系统导入 matplotlib将张量流导入为 tf

我收到此错误

导入错误:没有名为tensorflow"的模块

这是tensorflow包在我C盘的位置

C:UsersmynameAnaconda2envs	ensorflowLibsite-packages	ensorflow

当我去 Anaconda Navigator 时,似乎我必须选择 root、Python35 或 Tensorflow.看起来 Tensorflow 环境包含 Python35.

最近必须重新安装 Anaconda Navigator 启动器,可能是因为安装了 Tensorflow.也许如果有另一种方法可以在 Anaconda/Spyder IDE 中将环境设置为 Tensorflow,而不是 Navigator,它可能会有所帮助

tensorflow的安装方法

conda create --name tensorflow python=3.5;pip install --ignore-installed --upgrade tensorflow

我确实尝试过:卸载并重新安装protobuf,正如一些博客所建议的

我看到另一位 SO 用户在三月份问了同样的问题,但没有收到回复

解决方案

Python 3.5环境无法导入Tensorflow的原因是Anaconda没有将tensorflow包存储在同一个环境中.

一种解决方案是在 Anaconda 中创建一个新的独立环境,专门用于 TensorFlow 及其自己的 Spyder

conda create -n newenvt anaconda python=3.5激活新环境

然后将tensorflow安装到newenvt

我发现这本入门书很有帮助

I installed TensorFlow on my Windows Python 3.5 Anaconda environmentThe validation was successful (with a warning)

(tensorflow) C:>python

Python 3.5.3 |Intel Corporation| (default, Apr 27 2017, 17:03:30) [MSC v.1900 64 bit (AMD64)] on win32

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: W C:f_jenkinshomeworkspaceel-winMwindowsPY35ensorflowcoreplatformcpu_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'Hello, TensorFlow!'

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

I get this error

This is the location of the tensorflow package on my C drive

C:UsersmynameAnaconda2envs	ensorflowLibsite-packages	ensorflow

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 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

Method of installing tensorflow

conda create --name tensorflow python=3.5;
pip install --ignore-installed --upgrade tensorflow

I did try:uninstalling and reinstalling protobuf, as suggesed by some blogs

I see another SO user asked the same question in March, received no reply

解决方案

The reason Python 3.5 environment is unable to import Tensorflow is that Anaconda does not store the tensorflow package in the same environment.

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

and then install tensorflow into newenvt

I found this primer helpful

这篇关于Tensorflow 导入错误:没有名为“tensorflow"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:11