简体   繁体   English

我已经安装了 Tensorflow 但我无法在 Python 中导入它:ImportError: cannot import name 'descriptor' from 'google.protobuf'(未知位置)

[英]I have installed Tensorflow but I can not import it in Python: ImportError: cannot import name 'descriptor' from 'google.protobuf' (unknown location)

I have installed Tensorflow successfully in my Windows 10 Notebook:我已经在我的 Windows 10 笔记本中成功安装了 Tensorflow:

(base) C:\WINDOWS\system32>pip install tensorflow-gpu
Requirement already satisfied: tensorflow-gpu in c:\users\alienware\anaconda3\lib\site-packages (2.0.0)
Requirement already satisfied: gast==0.2.2 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (0.2.2)
Requirement already satisfied: opt-einsum>=2.3.2 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (3.1.0)
Requirement already satisfied: numpy<2.0,>=1.16.0 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (1.16.5)
Requirement already satisfied: keras-applications>=1.0.8 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (1.0.8)
Requirement already satisfied: keras-preprocessing>=1.0.5 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (1.1.0)
Requirement already satisfied: six>=1.10.0 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (1.12.0)
Requirement already satisfied: termcolor>=1.1.0 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (1.1.0)
Requirement already satisfied: tensorflow-estimator<2.1.0,>=2.0.0 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (2.0.0)
Requirement already satisfied: grpcio>=1.8.6 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (1.24.1)
Requirement already satisfied: google-pasta>=0.1.6 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (0.1.7)
Requirement already satisfied: wheel>=0.26 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (0.33.6)
Requirement already satisfied: protobuf>=3.6.1 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (3.10.0)
Requirement already satisfied: wrapt>=1.11.1 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (1.11.2)
Requirement already satisfied: tensorboard<2.1.0,>=2.0.0 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (2.0.0)
Requirement already satisfied: astor>=0.6.0 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (0.8.0)
Requirement already satisfied: absl-py>=0.7.0 in c:\users\alienware\anaconda3\lib\site-packages (from tensorflow-gpu) (0.8.1)
Requirement already satisfied: h5py in c:\users\alienware\anaconda3\lib\site-packages (from keras-applications>=1.0.8->tensorflow-gpu) (2.10.0)
Requirement already satisfied: setuptools in c:\users\alienware\anaconda3\lib\site-packages (from protobuf>=3.6.1->tensorflow-gpu) (41.4.0)
Requirement already satisfied: werkzeug>=0.11.15 in c:\users\alienware\anaconda3\lib\site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow-gpu) (0.16.0)
Requirement already satisfied: markdown>=2.6.8 in c:\users\alienware\anaconda3\lib\site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow-gpu) (3.1.1)

However, when I try to import it in Python I get an error message:但是,当我尝试在 Python 中导入它时,我收到一条错误消息:

C:\WINDOWS\system32>conda activate base

(base) C:\WINDOWS\system32>python
Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
>>>

When I run conda list I get:当我运行conda list我得到:

在此处输入图像描述

Update更新

I followed Rachayita's advise below but I have installed Tensorflow 1.4 and I want tensorflow-gpu 2.0我遵循了 Rachayita 的建议,但我已经安装了 Tensorflow 1.4,我想要 tensorflow-gpu 2.0

From my base Anaconda environment I uninstalled tensorflow-gpu 2.0 which was installed and then re-installed it with pip following the official tensorflow documentation.从我的基本 Anaconda 环境中,我卸载了已安装的 tensorflow-gpu 2.0,然后按照官方 tensorflow 文档使用 pip 重新安装它。

When I tried to import it in python I got the following error message:当我尝试在 python 中导入它时,我收到以下错误消息:

(base) C:\Users\Alienware>python
Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
2019-10-22 23:35:53.390099: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Alienware\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
    from tensorflow_core import *
  File "C:\Users\Alienware\Anaconda3\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\Alienware\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Users\Alienware\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Users\Alienware\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\Alienware\Anaconda3\lib\site-packages\tensorflow_core\python\__init__.py", line 52, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "C:\Users\Alienware\Anaconda3\lib\site-packages\tensorflow_core\core\framework\graph_pb2.py", line 7, in <module>
    from google.protobuf import descriptor as _descriptor
ImportError: cannot import name 'descriptor' from 'google.protobuf' (unknown location)

You should install it with Anaconda by running the following commands on the Anaconda prompt:您应该通过在 Anaconda 提示符下运行以下命令,将其与 Anaconda 一起安装:

> conda create -n tf-gpu tensorflow-gpu
> conda activate tf-gpu

Here is the complete documentation -https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/这是完整的文档 -https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/

You have to install tensorflow using pip install tensorflow and not tensorflow-gpu您必须使用 pip 安装 tensorflow 安装 tensorflow 而不是 tensorflow-gpu

Did you run "pip install tensorflow-gpu" after "conda activate base"?您是否在“conda activate base”之后运行了“pip install tensorflow-gpu”?

If not then that is what you need to do since tensorflow will not be installed in your virtual enviroment "base".如果不是,那么这就是您需要做的,因为 tensorflow 不会安装在您的虚拟环境“基础”中。

暂无
暂无

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

相关问题 ImportError:无法从“google”(未知位置)导入名称“search” - ImportError: cannot import name 'search' from 'google' (unknown location) ImportError:无法从“tensorflow.python”(未知位置)导入名称“tf2” - ImportError: cannot import name 'tf2' from 'tensorflow.python' (unknown location) ImportError:无法从“tensorflow.python.eager”(未知位置)导入名称“context” - ImportError: cannot import name 'context' from 'tensorflow.python.eager' (unknown location) 导入错误:无法从 python 中的“包”(未知位置)导入名称“方法” - ImportError: cannot import name 'method' from 'package' (unknown location) in python from google import google ImportError: cannot import name 'google' from 'google' (unknown location) - from google import google ImportError: cannot import name 'google' from 'google' (unknown location) 导入错误:虽然我安装了谷歌云视觉,但无法从“google.cloud.vision”导入名称“types” - ImportError: cannot import name 'types' from 'google.cloud.vision' though I have google cloud vision installed 如何修复 python 3.8.5。 错误“导入错误:无法从‘io’(未知位置)导入名称‘open_code’” - How do I fix python 3.8.5. error "ImportError: cannot import name 'open_code' from 'io' (unknown location)" google.protobuf导入错误 - google.protobuf import error 导入错误:无法从“tensorflow.keras.preprocessing”(未知位置)导入名称“image_dataset_from_directory” - ImportError: cannot import name 'image_dataset_from_directory' from 'tensorflow.keras.preprocessing' (unknown location) 导入错误:无法从“google.protobuf.internal”导入名称“builder” - ImportError: cannot import name 'builder' from 'google.protobuf.internal'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM