tensorflow - ubuntu 无法导入 Tensorflow
问题描述
系统信息
- Linux Ubuntu 16.04
- TensorFlow 版本:tensorflow-gpu 1.5
- Python版本:2.7
- 使用 virtualenv 安装:pip
- CUDA/cuDNN 版本:CUDA9.0 & CUDNN7.0
环境
- 使用 anaconda 创建一个名为 tf.
错误信息
(tf) ➜ ~ python
Python 2.7.18 |Anaconda, Inc.| (default, Jun 4 2021, 14:47:46)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/google/protobuf/descriptor.py", line 113
class DescriptorBase(metaclass=DescriptorMetaclass):
^
SyntaxError: invalid syntax
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/xander/anaconda3/envs/tf/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
ImportError: cannot import name pywrap_tensorflow
解决方案
如此链接中所述,您在与 TensorFlow 相同的目录中运行脚本。尝试将其移出,您应该会没事的。
例如,打开 Linux 命令行并执行刚刚复制到桌面的脚本
推荐阅读
- docker - Traefik 根本没有加载我的配置文件
- matlab - 是否可以实时从 MATLAB 函数向 Simulink 提供值?
- angular - Angular 9 rxJs - 如何使用组合/合并语句来检索可观察值并传递给另一个函数
- javascript - 验证数字 1、2 和 3 时出现问题
- lua - 错误:(20,63)Expected ')'(在第 55 列关闭 '('),得到 =
- unit-testing - 如何在另一个方法中存根
- android - 如何将在线数据库放入本地数据库
- python - 如何检查列表中字符串的一部分是否包含在Python中的另一个列表中
- javascript - 从 JavaScript For 循环创建动态 PHP 变量(回显)
- java - 2个不同版本的Guava在不同的模块层上,还是互相踩脚的