【问题标题】:error: could not create '/Library/Python/2.7/site-packages/xlrd': Permission denied错误:无法创建“/Library/Python/2.7/site-packages/xlrd”:权限被拒绝
【发布时间】:2013-08-13 02:47:39
【问题描述】:

我正在尝试在 mac 10.8.4 上安装 xlrd,以便能够通过 python 读取 excel 文件。

我已按照http://www.simplistix.co.uk/presentations/python-excel.pdf上的说明进行操作

我这样做了:

  1. 将文件夹解压到桌面

  2. 在终端中,cd 到解压后的文件夹

  3. $ python setup.py install

这是我得到的:

running install
running build
running build_py
creating build
creating build/lib
creating build/lib/xlrd
copying xlrd/__init__.py -> build/lib/xlrd
copying xlrd/biffh.py -> build/lib/xlrd
copying xlrd/book.py -> build/lib/xlrd
copying xlrd/compdoc.py -> build/lib/xlrd
copying xlrd/formatting.py -> build/lib/xlrd
copying xlrd/formula.py -> build/lib/xlrd
copying xlrd/info.py -> build/lib/xlrd
copying xlrd/licences.py -> build/lib/xlrd
copying xlrd/sheet.py -> build/lib/xlrd
copying xlrd/timemachine.py -> build/lib/xlrd
copying xlrd/xldate.py -> build/lib/xlrd
copying xlrd/xlsx.py -> build/lib/xlrd
creating build/lib/xlrd/doc
copying xlrd/doc/compdoc.html -> build/lib/xlrd/doc
copying xlrd/doc/xlrd.html -> build/lib/xlrd/doc
creating build/lib/xlrd/examples
copying xlrd/examples/namesdemo.xls -> build/lib/xlrd/examples
copying xlrd/examples/xlrdnameAPIdemo.py -> build/lib/xlrd/examples
running build_scripts
creating build/scripts-2.7
copying and adjusting scripts/runxlrd.py -> build/scripts-2.7
changing mode of build/scripts-2.7/runxlrd.py from 644 to 755
running install_lib
creating /Library/Python/2.7/site-packages/xlrd
error: could not create '/Library/Python/2.7/site-packages/xlrd': Permission denied

为什么权限被拒绝?谢谢

【问题讨论】:

    标签: python installation xlrd


    【解决方案1】:

    试试python setup.py install --user

    您不应该使用上面建议的sudo,原因有两个:

    1. 您允许互联网上任意不受信任的代码以 root 身份运行
    2. --user 标志传递给python setup.py install 会将包安装到用户拥有的目录。您的普通非 root 用户将无法访问 sudo pipsudo python setup.py 安装的文件

    【讨论】:

    • 如果我已经用 root 安装了软件包,我可以用chown -R username /Library/Python/2.7/site-packages 更改权限吗?或者你有什么建议?
    • 这不是我必须处理的事情,无论如何我也不会相信我的话 - 作为一个新问题提出来看看其他人要说什么:-)也许留下一个当你这样做时,链接到你的 Q
    【解决方案2】:

    试试sudo python setup.py install

    /Library 文件夹需要 root 权限才能访问。

    【讨论】:

    • 不要sudo!使用--user 标志
    • 在我的情况下(OpenELEC)没有 sudo,所以 --user 标志就是这样做的!
    【解决方案3】:

    试试virtualenv

    • sudo pip install virtualenvwrapper
    • mkvirtualenv
    • 工作中
    • python setup.py 安装

    【讨论】:

      猜你喜欢
      • 2017-09-25
      • 1970-01-01
      • 2014-02-07
      • 1970-01-01
      • 1970-01-01
      • 2017-10-09
      • 2018-09-19
      • 2023-03-13
      • 2015-05-12
      相关资源
      最近更新 更多