pkg_resources提取错误:无法提取文件到蛋缓存:[Errno 13] 权限被拒绝

1 投票
1 回答
1926 浏览
提问于 2025-04-18 18:28

我这几天一直在为一个问题苦恼,最近又碰到了一个死胡同:

我想卸载 cx_Oracle,重新开始。然后我找到了一篇文章,里面说要卸载它的方法是删除那个“egg”文件。

于是我就这么做了:

rm -rf /Users/xxx/.python-eggs/cx_Oracle-5.1.3-py2.7-macosx-10.8-x86_64.egg-tmp/

现在我意识到这是我理解能力的一个大失误,但事情已经发生了,就没办法了。

接着我尝试运行脚本,结果出现了:

 File "time_reporting.py", line 31, in <module>
    import cx_Oracle
  File "build/bdist.macosx-10.8-x86_64/egg/cx_Oracle.py", line 7, in <module>
  File "build/bdist.macosx-10.8-x86_64/egg/cx_Oracle.py", line 4, in __bootstrap__
  File "build/bdist.macosx-10.8-x86_64/egg/pkg_resources.py", line 951, in resource_filename
    err.manager        = self
  File "build/bdist.macosx-10.8-x86_64/egg/pkg_resources.py", line 1647, in get_resource_filename
    def get_importer(path_item):
  File "build/bdist.macosx-10.8-x86_64/egg/pkg_resources.py", line 1677, in _extract_resource
    except ImportError:
  File "build/bdist.macosx-10.8-x86_64/egg/pkg_resources.py", line 1017, in get_cache_path
    Resource providers should call this method ONLY after successfully
  File "build/bdist.macosx-10.8-x86_64/egg/pkg_resources.py", line 997, in extraction_error

pkg_resources.ExtractionError: Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

  [Errno 13] Permission denied: '/Users/xxx/.python-eggs/cx_Oracle-5.1.3-py2.7-macosx-10.8-x86_64.egg-tmp'

The Python egg cache directory is currently set to:

  /Users/xxx/.python-eggs

Perhaps your account does not have write access to this directory?  You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.

现在我完全不知道该怎么办了。我的环境是 Python 2.7.8,OSX 10.8.5。

1 个回答

0

目标目录的UNIX文件权限和所有权设置不正确。很可能是你以root用户身份安装了东西,这样这些目录就成了root用户拥有的。

在Python中,不要以root身份安装软件包,除非你真的知道自己在做什么。

使用UNIX的chmod和chown命令来修复目录权限

...或者用sudo删除这些目录,然后再不使用sudo重新安装软件包:

sudo rm -rf /Users/xxx/.python-eggs/

撰写回答