起因:
帮我可爱的妹子在windows电脑上,尝试跑通一个tensorflow的GAN代码
报错信息:
TypeError: expected bytes, Descriptor found
出错位置:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\python\__init__.py", line 55, in <module>
'tensorflow_estimator.python.estimator'))
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\python\tools\component_api_helper.py", line 56, in package_hook
child_pkg = importlib.import_module(child_package_str)
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow_estimator\__init__.py", line 8, in <module>
from tensorflow_estimator._api.v1 import estimator
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow_estimator\_api\v1\estimator\__init__.py", line 8, in <module>
from tensorflow_estimator._api.v1.estimator import experimental
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow_estimator\_api\v1\estimator\experimental\__init__.py", line 8, in <module>
from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow_estimator\python\estimator\__init__.py", line 25, in <module>
import tensorflow_estimator.python.estimator.estimator_lib
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow_estimator\python\estimator\estimator_lib.py", line 22, in <module>
from tensorflow_estimator.python.estimator.canned.baseline import BaselineClassifier
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow_estimator\python\estimator\canned\baseline.py", line 54, in <module>
from tensorflow.python.feature_column import feature_column as feature_column_lib
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\python\feature_column\feature_column.py", line 138, in <module>
from tensorflow.python.eager import context
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\python\eager\context.py", line 27, in <module>
from tensorflow.core.protobuf import config_pb2
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\core\protobuf\config_pb2.py", line 15, in <module>
from tensorflow.core.framework import cost_graph_pb2 as tensorflow_dot_core_dot_framework_dot_cost__graph__pb2
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\core\framework\cost_graph_pb2.py", line 15, in <module>
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\core\framework\tensor_shape_pb2.py", line 111, in <module>
__module__ = 'tensorflow.core.framework.tensor_shape_pb2'
TypeError: expected bytes, Descriptor found
分析:
从 __module__ = 'tensorflow.core.framework.tensor_shape_pb2 可以看到tensorflow系统文件出错
初步怀疑是tensorflow版本和电脑不匹配,所以尝试了多个版本tensorflow的安装:
使用代码可以查看版本:conda search --full-name tensorflow
tensorflow== (from versions: 1.2.0rc2, 1.2.0, 1.2.1, 1.3.0rc0, 1.3.0rc1, 1.3.0rc2, 1.3.0, 1.4.0rc0, 1.4.0rc1, 1.4.0, 1.5.0rc0, 1.5.0rc1, 1.5.0, 1.5.1, 1.6.0rc0, 1.6.0rc1, 1.6.0, 1.7.0rc0, 1.7.0rc1, 1.7.0, 1.7.1, 1.8.0rc0, 1.8.0rc1, 1.8.0, 1.9.0rc0, 1.9.0rc1, 1.9.0rc2, 1.9.0, 1.10.0rc0, 1.10.0rc1, 1.10.0, 1.11.0rc0, 1.11.0rc1, 1.11.0rc2, 1.11.0, 1.12.0rc0, 1.12.0rc1, 1.12.0rc2, 1.12.0, 1.12.2, 1.12.3, 1.13.0rc0, 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 2.0.0a0, 2.0.0b0, 2.0.0b1, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0, 2.1.0rc0)
pip install tensorflow
conda install tensorflow
各种试
命令自己给安了很多库,包括并不限于bleach tensorflow-tensorboard 等等
〉》〉》〉》〉》〉》〉》LONG TIME AGO 》〉》〉》〉〉》〉》〉》
错误终于变成了:
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 10, in <module>
from google.protobuf import descriptor_pb2
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\google\protobuf\descriptor_pb2.py", line 1839, in <module>
__module__ = 'google.protobuf.descriptor_pb2'
TypeError: expected bytes, Descriptor found
分析:
从__module__ = 'google.protobuf.descriptor_pb2'可以看出,错误是protobuf的问题。
本环境是python3,所以怀疑是1.protobuf版本过低,2.protobuf支持py2,需要装py3。所以:
pip install protobuf-py3
pip install --upgrade protobuf
重新运行,发现错误变化,说明上一个问题已解决,下一个环境有问题。。。(吐血)
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\python\__init__.py", line 77, in <module>
from tensorflow.python.estimator import estimator_lib as estimator
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\python\estimator\estimator_lib.py", line 24, in <module>
from tensorflow.python.estimator.inputs import inputs
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\python\estimator\inputs\inputs.py", line 23, in <module>
from tensorflow.python.estimator.inputs.pandas_io import pandas_input_fn
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\tensorflow\python\estimator\inputs\pandas_io.py", line 28, in <module>
import pandas as pd
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\pandas\__init__.py", line 30, in <module>
from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\pandas\_libs\__init__.py", line 3, in <module>
from .tslibs import (
File "C:\Users\HIT\Anaconda3\envs\sgan\lib\site-packages\pandas\_libs\tslibs\__init__.py", line 3, in <module>
from .conversion import localize_pydatetime, normalize_date
File "pandas/_libs/tslibs/conversion.pyx", line 234, in init pandas._libs.tslibs.conversion
AttributeError: type object 'pandas._libs.tslibs.conversion._TSObject' has no attribute '__reduce_cython__'
查博客,查到:
pip install pandas==0.23.0
再次重新检查
>>> import tensorflow
>>> hello = tensorflow.constant('helllllllllo')
>>> sess = tf.session()
>>> sess = tensorflow.Session()
>>> print(sess.run(hello))
b'helllllllllo'
终于成功。。。
普天同庆!!!
心得:
人生苦短,我用Pytorch。。。tensorflow路转黑(哭泣)