尝试了其他方法不太有效,只能重新卸载安装一次protobuf
(base) sun@sun-QiTianM415-N000:~/tool$ pip uninstall protobuf
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Uninstalling protobuf-3.7.0:
Would remove:
/usr/local/lib/python2.7/dist-packages/google/protobuf/*
/usr/local/lib/python2.7/dist-packages/protobuf-3.7.0-py2.7-nspkg.pth
/usr/local/lib/python2.7/dist-packages/protobuf-3.7.0.dist-info/*
Proceed (y/n)? y
ERROR: Exception:
Traceback (most recent call last):
File "/home/sun/anaconda2/lib/python2.7/site-packages/pip/_internal/cli/base_command.py", line 188, in main
status = self.run(options, args)
File "/home/sun/anaconda2/lib/python2.7/site-packages/pip/_internal/commands/uninstall.py", line 75, in run
auto_confirm=options.yes, verbose=self.verbosity > 0,
File "/home/sun/anaconda2/lib/python2.7/site-packages/pip/_internal/req/req_install.py", line 831, in uninstall
uninstalled_pathset.remove(auto_confirm, verbose)
File "/home/sun/anaconda2/lib/python2.7/site-packages/pip/_internal/req/req_uninstall.py", line 388, in remove
moved.stash(path)
File "/home/sun/anaconda2/lib/python2.7/site-packages/pip/_internal/req/req_uninstall.py", line 277, in stash
renames(path, new_path)
File "/home/sun/anaconda2/lib/python2.7/site-packages/pip/_internal/utils/misc.py", line 402, in renames
shutil.move(old, new)
File "/home/sun/anaconda2/lib/python2.7/shutil.py", line 314, in move
rmtree(src)
File "/home/sun/anaconda2/lib/python2.7/shutil.py", line 266, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "/home/sun/anaconda2/lib/python2.7/shutil.py", line 264, in rmtree
os.remove(fullname)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/google/protobuf/service_reflection.pyc'
遇到类似的OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/
问题,表示权限不许,解决方法如下:
>> sudo chown -R sun(用户名) /usr/local/lib/python2.7
(base) sun@sun-QiTianM415-N000:~/tool$ pip uninstall protobuf DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Uninstalling protobuf-3.7.0:
Would remove:
/usr/local/lib/python2.7/dist-packages/google/protobuf/*
/usr/local/lib/python2.7/dist-packages/protobuf-3.7.0-py2.7-nspkg.pth
/usr/local/lib/python2.7/dist-packages/protobuf-3.7.0.dist-info/*
Proceed (y/n)? y
Successfully uninstalled protobuf-3.7.0
>> python
>> import tensorflow as tf
>>
`