41

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

I have followed the instructions on 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

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

Sammy
  • 669
  • 2
  • 8
  • 13

3 Answers3

155

Try python setup.py install --user

You shouldn't use sudo as suggested above for two reasons:

  1. You're allowing arbitrary untrusted code off the internet to be run as root
  2. Passing the --user flag to python setup.py install will install the package to a user-owned directory. Your normal non-root user won't be able to access the files installed by sudo pip or sudo python setup.py
mbigras
  • 7,664
  • 11
  • 50
  • 111
Louis Maddox
  • 5,226
  • 5
  • 36
  • 66
  • if I already installed packages with root there, can I just change the permissions with `chown -R username /Library/Python/2.7/site-packages` or what do you recommend? – Chris May 22 '15 at 13:10
  • 1
    Not something I've had to deal with, and I wouldn't take my word on that anyway - ask it as a new question and see what other people have to say :-) Maybe leave a link to your Q here when you do – Louis Maddox May 25 '15 at 15:47
6

try sudo python setup.py install

the /Library folder needs root permission to be accessed.

arynhard
  • 542
  • 1
  • 5
  • 11
4

Try in a virtualenv:

  • sudo pip install virtualenvwrapper
  • mkvirtualenv
  • workon
  • python setup.py install
Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
Nitin
  • 41
  • 1