简体   繁体   English

tensorflow安装问题:ImportError:没有名为tensorflow的模块

[英]tensorflow installation issues:ImportError: No module named tensorflow

environments: Ubuntu 14.04(64bit) Python2.7.11 环境:Ubuntu 14.04(64位)Python2.7.11

Firstly, I installed tensorflow in the way of Virtualenz installation. 首先,我安装了Virtualenz安装的tensorflow。

$ sudo apt-get install python-pip python-dev python-virtualenv
$ virtualenv --system-site-packages ~/tensorflow
$ source ~/tensorflow/bin/activate  
$export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl

$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl

$ pip install --upgrade $TF_BINARY_URL

and then, I test my installation and some issue appear. 然后,我测试我的安装并出现一些问题。 I know I didn't install tensorflow successfully. 我知道我没有成功安装tensorflow。 import tensorflow Traceback (most recent call last): File "", line 1, in ImportError: No module named tensorflow import tensorflow Traceback(最近一次调用last):ImportError中的文件“”,第1行:没有名为tensorflow的模块

import tensorflow as tf Traceback (most recent call last): File "", line 1, in ImportError: No module named tensorflow 跟踪tensorflow为tf Traceback(最近一次调用last):在ImportError中的文件“”,第1行:没有名为tensorflow的模块

I don't know how to solve the problem. 我不知道如何解决这个问题。 Please help me, it cost me one day. 请帮助我,花了我一天的时间。 I tried to uninstall tensorflow and then I installed in the way of pip installation. 我试图卸载tensorflow然后我以pip安装的方式安装。 But I get the same error. 但我得到了同样的错误。 The protocbuf is 3.1.0. protocbuf是3.1.0。

Are you running python in the same virtual environment you installed tensorflow in? 您是否在安装了tensorflow的同一虚拟环境中运行python?

To access your tensorflow installation, you have to first "activate" the virtualenv in any new terminals, as follows: 要访问tensorflow安装,您必须首先在任何新终端中“激活”virtualenv,如下所示:

source ~/tensorflow/bin/activate
python
import tensorflow as tf

If you run the above in a new terminal, does it solve your problem? 如果您在新终端中运行上述内容,它是否可以解决您的问题?

When you did $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl 当您执行$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl

this step you are specifying that you are going to use Nvidia card. 这一步你指定你将使用Nvidia卡。 To run tensorflow with GPU(Nvidia graphics card) you need to satisfy all Nvidia requirements 要使用GPU(Nvidia显卡)运行tensorflow,您需要满足所有Nvidia要求

Nvidia requires some special privileges to its CUDA cores Nvidia需要对其CUDA核心有一些特殊权限

You also need to check for Cuda pathnames to the LD_LIBRARY_PATH environment variable, check in Nvidia Documentation .Also, you need to install an profiling support, this can be done by libcupti-dev library, which is the NVIDIA CUDA Profile Tools Interface. 您还需要检查LD_LIBRARY_PATH环境变量的Cuda路径名,检查Nvidia文档 。还需要安装分析支持,这可以通过libcupti-dev库完成,这是NVIDIA CUDA Profile Tools接口。 This library provides advanced profiling support. 该库提供高级分析支持。 To install this library, issue the following command: sudo apt-get install libcupti-dev 要安装此库,请发出以下命令: sudo apt-get install libcupti-dev

But if you want to run tensorflow in CPU mode only, do not specify $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl .With this you are overriding TF_BINARY_URL variable to use Nvidia CUDA core So, to use CPU from all your steps remove $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl and include only $export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl and reinstall 但是如果你只想在CPU模式下运行tensorflow,请不要指定$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl .With这是你要覆盖TF_BINARY_URL变量以使用Nvidia CUDA核心所以,要从所有步骤中使用CPU,请删除$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl并仅包含$export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl并重新安装

I hope this should clear the problem 我希望这应该清除问题

In case, your prerequisite python packages are not installed properly, check several things. 如果您的先决条件python包未正确安装,请检查几件事。

$ source $HOME/tensorflow/bin/activate
$ which python
$ which pip

please check these binaries are in the path $HOME/tensorflow/bin/activate . 请检查这些二进制文件是否在路径$HOME/tensorflow/bin/activate If so, try 如果是这样,试试吧

$ pip install -I --upgrade $TF_BINARY_URL

where -I option forces to install packages. 其中-I选项强制安装包。

INSTALLATION OF TENSORFLOW ON UBUNTU 18.04 在UBUNTU 18.04安装TENSORFLOW

download anaconda python package 下载anaconda python包

install it via shell using bash 使用bash通过shell安装它

$bash anaconda*.sh

editing the .bashrc script //location home 编辑.bashrc脚本//位置主页

$sudo apt-get install python3-pip
$sudo apt-get update
$cd
$nano .bashrc

nano is the text editor insert the given line at the end of the file nano是文本编辑器,在文件末尾插入给定行

export PATH=-/anaconda3/bin:$PATH

create a virtual environment using conda 使用conda创建虚拟环境

$conda create -n myenv python=3.5

//SPECIFY THE VERSION REQUIRED DO NOT USE 3.7 AS THERE IS A COMPATIBLITY ISSUE WITH TENSORFLOW 10 //指定所需的版本不要使用3.7由于TENSORFLOW 10存在兼容性问题

$source activate myenv
$pip install -U tensorflow
$python
>>import tensorflow as tf
>>  //get this prompt without an error it means the installation is successful
>>exit()
source deactivate

fully tested if an issue arises do let me know whenever you install python packages i would suggest to do it in a virtual environment 完全测试如果出现问题,请在安装python软件包时告诉我,我建议在虚拟环境中进行

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

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