首页 > 解决方案 > 安装后没有名为 tensorflow 的模块?

问题描述

我安装了 tensorflow-gpu,但在 Pycharm 中出现错误:

ModuleNotFoundError: No module named 'tensorflow'

我在终端签入:

$ pip3 list|grep tensorflow
tensorflow-gpu                     1.4.0     
tensorflow-tensorboard             0.4.0

编辑:(使用venv安装后):

Successfully installed tensorflow-gpu-1.12.0
(venv) wojtek@wojtek-GF63-8RC:~$ python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
2018-12-17 21:49:14.893016: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2018-12-17 21:49:14.961123: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:964] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-12-17 21:49:14.961466: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties: 
name: GeForce GTX 1050 major: 6 minor: 1 memoryClockRate(GHz): 1.493
pciBusID: 0000:01:00.0
totalMemory: 3.95GiB freeMemory: 3.58GiB
2018-12-17 21:49:14.961479: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2018-12-17 21:49:15.148507: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-12-17 21:49:15.148538: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988]      0 
2018-12-17 21:49:15.148544: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0:   N 
2018-12-17 21:49:15.148687: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3306 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1)
tf.Tensor(918.94904, shape=(), dtype=float32)

标签: tensorflowpycharm

解决方案


您需要配置解释器src

1) 在 Project Interpreters 页面中,选择已配置的解释器或虚拟环境之一。

2) 单击编辑。

3) 在打开的 Edit Python Interpreter 对话框中,键入所需的解释器名称。更改口译员姓名

在名称字段中指定的 Python 解释器名称在可用解释器列表中变得可见。

如有必要,更改 Python 可执行文件的路径。


推荐阅读