2

I tried to install the python library openpyxl using pip by typing into the terminal:

    pip install openpyxl

But it was not executed properly. It threw an exception:

    Successfully built openpyxl jdcal et-xmlfile
    Installing collected packages: jdcal, et-xmlfile, openpyxl
    Exception:
    Traceback (most recent call last):
    File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
    File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
    File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
    File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
    File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
    File "/Library/Python/2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
    File "/Library/Python/2.7/site-packages/pip/wheel.py", line 323, in clobber
    shutil.copyfile(srcfile, destfile)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
    IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/jdcal.py'
  • Possible duplicate of [pip is not able to install packages correctly: Permission denied error](https://stackoverflow.com/questions/25816674/pip-is-not-able-to-install-packages-correctly-permission-denied-error) – Si Mon Nov 23 '17 at 11:54

4 Answers4

7

Best way is probably to use pip install <libname> --user

Meaning in your case use pip install openpyxel --user

This installs the package for your user and that is safe. Also you have probably the right of installing the package for the user.

The permission error you have encountered is a frequent problem. As can be seen here: pip is not able to install packages correctly: Permission denied error and here error: could not create '/usr/local/lib/python2.7/dist-packages/virtualenv_support': Permission denied

Using the sudo pip command is not considered as safe as explained here: What are the risks of running 'sudo pip'?

Si Mon
  • 397
  • 3
  • 16
4

Your user doesn't have write permissions in the Python installation folder.

To fix it, run pip as root:

sudo pip install openpyxl

fedterzi
  • 1,105
  • 7
  • 17
0

Your account does not have write access to this directory?.

  1. If the installation directory is a system-owned directory, you may need to sign in as the administrator or "root" account.

    sudo pip install openpyxl

  2. If you do not have administrative access to this machine, you may wish to choose a different installation directory, preferably one that is listed in your PYTHON_PATH environment variable.

  3. easier way: change that dir permission:

    chmod +a 'user:YOUR_USER_NAME allow add_subdirectory,add_file,delete_child,directory_inherit' /Library/Python/2.7/site-packages

Luckie Hao
  • 99
  • 4
-1

Change security setting of site-packages folder to "Full Control" for your user and re run pip install openpyxl

Jazz
  • 1
  • 1
    There are better ways to do this than change security settings. `pip install --user` is one of them. – Munir Dec 25 '17 at 21:34