[英]Why “No module named tensorflow” when I installed tensorflow?
I use sudo pip install tensorflow-1.7.0rc0-cp27-cp27mu-manylinux1_x86_64.whl
in centos7,python version is 2.7.14
我在centos7中使用sudo pip install tensorflow-1.7.0rc0-cp27-cp27mu-manylinux1_x86_64.whl
manylinux1_x86_64.whl,python版本是2.7.14
I get successfully installed tensorflow,but when I run import tensorflow as tf
,I get a error:No module named tensorflow 我成功安装了tensorflow,但是当我将import tensorflow as tf
运行时,出现错误:没有名为tensorflow的模块
what should I do? 我该怎么办? thanks! 谢谢!
As mentioned in the comments you best method for installing pyhton packages is to use a virtual environment. 如评论中所述,安装pyhton软件包的最佳方法是使用虚拟环境。 For a simple way to do this you can install Minicaonda for linux x86
using the following command: 作为一种简单的方法,您可以使用以下命令为linux x86
安装Minicaonda :
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash ./Miniconda3-latest-Linux-x86_64.sh
Then it is worth reading the instructions on using conda , to set up a virtual environment called tensorflow
. 然后值得阅读有关使用conda来建立名为tensorflow
的虚拟环境的tensorflow
。 But the basic command should be: 但是基本命令应该是:
conda create -n tensorflow python=3.6 tensorflow
provided you want to use tensorflow with python3.6. 如果您想在python3.6中使用tensorflow。 Then activate your tensorflow conda environment: 然后激活您的tensorflow conda环境:
source activate tensorflow
and you should be able to import tensorflow without issue. 并且您应该能够顺利导入tensorflow。
(tensorflow) user@machine:~$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.