安装tensorflow时出现ImportError: No module named google.protobuf

本文详细记录了解决在Python环境中卸载protobuf包时遇到的权限拒绝错误的过程。通过使用sudo命令更改文件所有者,成功解决了OSError: [Errno 13] Permission denied的问题,确保了后续操作的顺利进行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

尝试了其他方法不太有效,只能重新卸载安装一次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
>>

`

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值