错误:无法创建“/Library/Python/2.7/site-packages/xlrd”:权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18199853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:11:36  来源:igfitidea点击:

error: could not create '/Library/Python/2.7/site-packages/xlrd': Permission denied

pythoninstallationxlrd

提问by Sammy

I'm trying to install xlrd on mac 10.8.4 to be able to read excel files through python.

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

I have followed the instructions on http://www.simplistix.co.uk/presentations/python-excel.pdf

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

I did this:

我这样做了:

  1. unzipped the folder to desktop

  2. in terminal, cd to the unzipped folder

  3. $ python setup.py install

  1. 将文件夹解压到桌面

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

  3. $ python setup.py 安装

This is what I get:

这就是我得到的:

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

Why is permission denied? Thanks

为什么权限被拒绝?谢谢

采纳答案by arynhard

try sudo python setup.py install

尝试 sudo python setup.py install

the /Library folder needs root permission to be accessed.

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

回答by Louis Maddox

Try python setup.py install --user

尝试 python setup.py install --user

You shouldn't use sudoas suggested above for two reasons:

sudo由于两个原因,您不应该按照上述建议使用:

  1. You're allowing arbitrary untrusted code off the internet to be run as root
  2. Passing the --userflag to python setup.py installwill install the package to a user-owned directory. Your normal non-root user won't be able to access the files installed by sudo pipor sudo python setup.py
  1. 您允许 Internet 上的任意不受信任的代码以 root 身份运行
  2. 传递--user标志 topython setup.py install会将包安装到用户拥有的目录。您的普通非 root 用户将无法访问由sudo pipsudo python setup.py

回答by Nitin

Try in a virtualenv:

尝试virtualenv

  • sudo pip install virtualenvwrapper
  • mkvirtualenv
  • workon
  • python setup.py install
  • 须藤 pip 安装 virtualenvwrapper
  • mkvirtualenv
  • 从事于
  • python setup.py 安装