Python TensorFlow的导入错误和属性错误

Python TensorFlow的导入错误和属性错误,python,tensorflow,anaconda,Python,Tensorflow,Anaconda,背景 我正在尝试使用GAN神经网络(我是Python和机器学习的初学者),我需要Tensorflow 问题 我已尝试使用TensorFlow,但无法安装。我读过关于各种错误的文章,并测试过这些解决方案,但我相信这个案例是不同的 我试过的(按时间顺序) 1。普通重启 a) 关闭Jupyter笔记本的所有选项卡 b) 关闭蟒蛇导航器 c) 重新启动Jupyter笔记本电脑 d) 重新运行代码 结果:导入错误:无模块 2。重新安装tf a) 重复1a和1b b) 打开蟒蛇提示 c) pip安装tens

背景

我正在尝试使用GAN神经网络(我是Python和机器学习的初学者),我需要Tensorflow

问题

我已尝试使用TensorFlow,但无法安装。我读过关于各种错误的文章,并测试过这些解决方案,但我相信这个案例是不同的

我试过的(按时间顺序) 1。普通重启

a) 关闭Jupyter笔记本的所有选项卡
b) 关闭蟒蛇导航器
c) 重新启动Jupyter笔记本电脑
d) 重新运行代码

结果:
导入错误:无模块

2。重新安装tf

a) 重复1a和1b
b) 打开蟒蛇提示
c)
pip安装tensorflow

结果:
模块已安装

3。签出导航器

Tensorflow安装在我拥有的所有环境中

4。重新安装tf(取2)

a) 重复1a和1b
b) 打开蟒蛇提示
c)
conda安装-c conda forge tensorflow

结果:
EnvironmentNotWritableError:当前用户没有对目标环境的写入权限。环境位置:C:\ProgramData\

5。以管理员身份运行

a) 重复1a和1b
b) 打开蟒蛇提示
c)
conda安装-c conda forge tensorflow

结果:

Preparing transaction: done
Verifying transaction: done
Executing transaction: <after some text> done
AttributeError                            Traceback (most recent call last)
<ipython-input-6-efbffb1990be> in <module>
----> 1 import tensorflow as tf
      2 import numpy as np
      3 import matplotlib.pyplot as plt
      4 import os
      5 import glob2

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\__init__.py in <module>
     22 
     23 # pylint: disable=g-bad-import-order
---> 24 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
     25 
     26 from tensorflow._api.v1 import app

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>
     80 from tensorflow.python import data
     81 from tensorflow.python import distribute
---> 82 from tensorflow.python import keras
     83 from tensorflow.python.feature_column import feature_column_lib as feature_column
     84 from tensorflow.python.layers import layers

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\__init__.py in <module>
     23 
     24 from tensorflow.python.keras import activations
---> 25 from tensorflow.python.keras import applications
     26 from tensorflow.python.keras import backend
     27 from tensorflow.python.keras import callbacks

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\applications\__init__.py in <module>
     24 from tensorflow.python.keras import backend
     25 from tensorflow.python.keras import engine
---> 26 from tensorflow.python.keras import layers
     27 from tensorflow.python.keras import models
     28 from tensorflow.python.keras import utils

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\__init__.py in <module>
     27 
     28 # Advanced activations.
---> 29 from tensorflow.python.keras.layers.advanced_activations import LeakyReLU
     30 from tensorflow.python.keras.layers.advanced_activations import PReLU
     31 from tensorflow.python.keras.layers.advanced_activations import ELU

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\advanced_activations.py in <module>
     25 from tensorflow.python.keras.engine.base_layer import Layer
     26 from tensorflow.python.keras.engine.input_spec import InputSpec
---> 27 from tensorflow.python.keras.utils import tf_utils
     28 from tensorflow.python.ops import math_ops
     29 from tensorflow.python.util.tf_export import tf_export

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\utils\__init__.py in <module>
     36 from tensorflow.python.keras.utils.layer_utils import get_source_inputs
     37 from tensorflow.python.keras.utils.losses_utils import squeeze_or_expand_dimensions
---> 38 from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model
     39 from tensorflow.python.keras.utils.np_utils import normalize
     40 from tensorflow.python.keras.utils.np_utils import to_categorical

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\utils\multi_gpu_utils.py in <module>
     20 from tensorflow.python.framework import ops
     21 from tensorflow.python.keras import backend as K
---> 22 from tensorflow.python.keras.engine.training import Model
     23 from tensorflow.python.ops import array_ops
     24 from tensorflow.python.util.tf_export import tf_export

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in <module>
     40 from tensorflow.python.keras.engine import training_generator
     41 from tensorflow.python.keras.engine import training_utils
---> 42 from tensorflow.python.keras.engine.network import Network
     43 from tensorflow.python.keras.optimizer_v2 import optimizer_v2
     44 from tensorflow.python.keras.utils import data_utils

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\network.py in <module>
     38 from tensorflow.python.keras.engine import base_layer
     39 from tensorflow.python.keras.engine import base_layer_utils
---> 40 from tensorflow.python.keras.engine import saving
     41 from tensorflow.python.keras.engine import training_utils
     42 from tensorflow.python.keras.utils import generic_utils

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\saving.py in <module>
     36 # pylint: disable=g-import-not-at-top
     37 try:
---> 38   import h5py
     39   HDF5_OBJECT_HEADER_LIMIT = 64512
     40 except ImportError:

C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py in <module>
     34 _errors.silence_errors()
     35 
---> 36 from ._conv import register_converters as _register_converters
     37 _register_converters()
     38 

h5py\h5r.pxd in init h5py._conv()

h5py\h5r.pyx in init h5py.h5r()

AttributeError: type object 'h5py.h5r.Reference' has no attribute '__reduce_cython__'
准备事务:完成
验证事务:完成
执行事务:完成
6。在Jupyter跑步

该代码目前与TF无关,但仍然不起作用

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import os
import glob2

font_lib = glob2.glob('**/*.ttf', recursive=True)

count = 0
for f in font_lib:
    count = count + 1
    if count < 10:
        print (f)
    else:
        break
print ("done")
将tensorflow导入为tf
将numpy作为np导入
将matplotlib.pyplot作为plt导入
导入操作系统
导入全球2
font_lib=glob2.glob('***.ttf',recursive=True)
计数=0
对于字体库中的f:
计数=计数+1
如果计数小于10:
印刷品(f)
其他:
打破
打印(“完成”)
结果:

Preparing transaction: done
Verifying transaction: done
Executing transaction: <after some text> done
AttributeError                            Traceback (most recent call last)
<ipython-input-6-efbffb1990be> in <module>
----> 1 import tensorflow as tf
      2 import numpy as np
      3 import matplotlib.pyplot as plt
      4 import os
      5 import glob2

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\__init__.py in <module>
     22 
     23 # pylint: disable=g-bad-import-order
---> 24 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
     25 
     26 from tensorflow._api.v1 import app

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>
     80 from tensorflow.python import data
     81 from tensorflow.python import distribute
---> 82 from tensorflow.python import keras
     83 from tensorflow.python.feature_column import feature_column_lib as feature_column
     84 from tensorflow.python.layers import layers

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\__init__.py in <module>
     23 
     24 from tensorflow.python.keras import activations
---> 25 from tensorflow.python.keras import applications
     26 from tensorflow.python.keras import backend
     27 from tensorflow.python.keras import callbacks

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\applications\__init__.py in <module>
     24 from tensorflow.python.keras import backend
     25 from tensorflow.python.keras import engine
---> 26 from tensorflow.python.keras import layers
     27 from tensorflow.python.keras import models
     28 from tensorflow.python.keras import utils

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\__init__.py in <module>
     27 
     28 # Advanced activations.
---> 29 from tensorflow.python.keras.layers.advanced_activations import LeakyReLU
     30 from tensorflow.python.keras.layers.advanced_activations import PReLU
     31 from tensorflow.python.keras.layers.advanced_activations import ELU

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\advanced_activations.py in <module>
     25 from tensorflow.python.keras.engine.base_layer import Layer
     26 from tensorflow.python.keras.engine.input_spec import InputSpec
---> 27 from tensorflow.python.keras.utils import tf_utils
     28 from tensorflow.python.ops import math_ops
     29 from tensorflow.python.util.tf_export import tf_export

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\utils\__init__.py in <module>
     36 from tensorflow.python.keras.utils.layer_utils import get_source_inputs
     37 from tensorflow.python.keras.utils.losses_utils import squeeze_or_expand_dimensions
---> 38 from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model
     39 from tensorflow.python.keras.utils.np_utils import normalize
     40 from tensorflow.python.keras.utils.np_utils import to_categorical

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\utils\multi_gpu_utils.py in <module>
     20 from tensorflow.python.framework import ops
     21 from tensorflow.python.keras import backend as K
---> 22 from tensorflow.python.keras.engine.training import Model
     23 from tensorflow.python.ops import array_ops
     24 from tensorflow.python.util.tf_export import tf_export

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in <module>
     40 from tensorflow.python.keras.engine import training_generator
     41 from tensorflow.python.keras.engine import training_utils
---> 42 from tensorflow.python.keras.engine.network import Network
     43 from tensorflow.python.keras.optimizer_v2 import optimizer_v2
     44 from tensorflow.python.keras.utils import data_utils

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\network.py in <module>
     38 from tensorflow.python.keras.engine import base_layer
     39 from tensorflow.python.keras.engine import base_layer_utils
---> 40 from tensorflow.python.keras.engine import saving
     41 from tensorflow.python.keras.engine import training_utils
     42 from tensorflow.python.keras.utils import generic_utils

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\saving.py in <module>
     36 # pylint: disable=g-import-not-at-top
     37 try:
---> 38   import h5py
     39   HDF5_OBJECT_HEADER_LIMIT = 64512
     40 except ImportError:

C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py in <module>
     34 _errors.silence_errors()
     35 
---> 36 from ._conv import register_converters as _register_converters
     37 _register_converters()
     38 

h5py\h5r.pxd in init h5py._conv()

h5py\h5r.pyx in init h5py.h5r()

AttributeError: type object 'h5py.h5r.Reference' has no attribute '__reduce_cython__'
AttributeError回溯(最近一次调用)
在里面
---->1导入tensorflow作为tf
2作为np导入numpy
3将matplotlib.pyplot作为plt导入
4导入操作系统
5进口全球2
C:\ProgramData\Anaconda3\lib\site packages\tensorflow\\uuuuu init\uuuuuu.py in
22
23#pylint:disable=g-bad-import-order
--->24从tensorflow.python导入pywrapu tensorflow35; pylint:disable=未使用的导入
25
26来自tensorflow.\u api.v1导入应用程序
C:\ProgramData\Anaconda3\lib\site packages\tensorflow\python\\uuuu init\uuuuu.py in
80从tensorflow.python导入数据
81从tensorflow.python导入分发
--->82从tensorflow.python导入keras
83从tensorflow.python.feature_column导入feature_column_lib作为feature_column
84从tensorflow.python.layers导入图层
C:\ProgramData\Anaconda3\lib\site packages\tensorflow\python\keras\\uuuuu init\uuuuuuu.py in
23
24来自tensorflow.python.keras导入激活
--->25来自tensorflow.python.keras导入应用程序
26从tensorflow.python.keras导入后端
27从tensorflow.python.keras导入回调
C:\ProgramData\Anaconda3\lib\site packages\tensorflow\python\keras\applications\\uuuu init\uuuuu.py in
24从tensorflow.python.keras导入后端
25来自tensorflow.python.keras导入引擎
--->26从tensorflow.python.keras导入层
27来自tensorflow.python.keras导入模型
28来自tensorflow.python.keras导入utils
C:\ProgramData\Anaconda3\lib\site packages\tensorflow\python\keras\layers\\uuuu init\uuuuu.py in
27
28#高级激活。
--->29从tensorflow.python.keras.layers.advanced_激活导入LeakyReLU
30从tensorflow.python.keras.layers.advanced_激活导入预处理
31从tensorflow.python.keras.layers.advanced_激活导入ELU
中的C:\ProgramData\Anaconda3\lib\site packages\tensorflow\python\keras\layers\advanced\u activations.py
25来自tensorflow.python.keras.engine.base_层导入层
26来自tensorflow.python.keras.engine.input\u spec导入InputSpec
--->27从tensorflow.python.keras.utils导入tf_utils
28从tensorflow.python.ops导入数学运算
29来自tensorflow.python.util.tf_导出tf_导出
C:\ProgramData\Anaconda3\lib\site packages\tensorflow\python\keras\utils\\uuuuu init\uuuuu.py in
36从tensorflow.python.keras.utils.layer\u utils导入获取\u源\u输入
37来自tensorflow.python.keras.utils.loss\u utils导入压缩或扩展维度
--->38从tensorflow.python.keras.utils.multi_gpu utils导入multi_gpu模型
39从tensorflow.python.keras.utils.np_utils导入规范化
40从tensorflow.python.keras.utils.np\u utils导入到\u category
C:\ProgramData\Anaconda3\lib\site packages\tensorflow\python\keras\utils\multi\u gpu\u utils.py in
20来自tensorflow.python.framework导入操作
21从tensorflow.python.keras导入后端为K
--->22来自tensorflow.python.keras.engine.training导入模型
23从tensorflow.python.ops导入数组
24来自tensorflow.python.util.tf_导出tf_导出
C:\ProgramData\Anaconda3\lib\site packages\tensorflow\python\keras\engine\training.py in
40来自tensorflow.python.keras.engine导入培训\u生成器
41来自tensorflow.python.keras.engine导入培训工具
--->42来自tensorflow.python.keras.engine.network导入网络
43来自tensorflow.python.keras.optimizer\u v2导入优化器\u v2
44从tensorflow.python.keras.utils导入数据
中的C:\ProgramData\Anaconda3\lib\site packages\tensorflow\python\keras\engine\network.py
38来自tensorflow.python.keras.engine导入基础层
39来自tensorflow.python.keras.engine导入基础层
--->40来自tensorflow.python.keras.engine导入保存
41来自tensorflow.python.keras.engine导入培训工具
42从tensorflow.python.keras.utils导入通用\u utils
C:\ProgramData\Anaconda3