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

2024-04-24 23:06:21 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

我做到了:

  1. 将文件夹解压缩到桌面

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

  3. $python setup.py安装

这就是我得到的:

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

为什么拒绝许可?谢谢


Tags: installpybuildcreating文件夹doclibhtml
3条回答

尝试sudo python setup.py install

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

virtualenv中尝试:

  • sudo pip安装virtualenvwrapper
  • mkvirtualenv公司
  • 修井
  • python setup.py安装

尝试python setup.py install --user

您不应该使用sudo,这有两个原因:

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

相关问题 更多 >