为什么在安装tensorflow时“没有名为tensorflow的模块”?

2024-09-27 04:29:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我在centos7中使用sudopip install tensorflow-1.7.0rc0-cp27-cp27mu-manylinux1_x86_64.whl,python版本是2.7.14

enter image description here

我成功地安装了tensorflow,但是当我运行import tensorflow as tf时,我得到一个错误:没有模块名为tensorflow

enter image description here

我该怎么办?谢谢!在


Tags: 模块installimport版本tftensorflowas错误
1条回答
网友
1楼 · 发布于 2024-09-27 04:29:20

正如评论中提到的,安装pyton包的最佳方法是使用虚拟环境。为了实现这一点,您可以使用以下命令为linux x86安装Minicaonda

wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash ./Miniconda3-latest-Linux-x86_64.sh

然后值得阅读instructions on using conda,以建立一个名为tensorflow的虚拟环境。但基本命令应该是:

^{pr2}$

如果你想在python3.6中使用tensorflow。然后激活tensorflow conda环境:

^{3}$

你应该可以导入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
>>>

相关问题 更多 >

    热门问题