7

When trying to enable linting with Pylint, and format on save with autopep8, neither will install because of a permission denied error.

Pylint:

IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/mccabe.py'

Autopep8:

IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pep8.py'
swade
  • 668
  • 2
  • 7
  • 15

3 Answers3

9

You can press ⬆ (up arrow key) in the terminal tab after the install fails to return to the command that it ran. In this case:

/usr/bin/python -m pip install pylint

Press fn+⬅ (left arrow key) to jump to the beginning of the line, then insert a 'sudo ' (no quotes, but including the trailing space) in front of the command, and press enter to re-run the command as root -- it should look like this:

sudo /usr/bin/python -m pip install pylint

You will be prompted for your password then the package will be installed without permissions errors.

user423430
  • 3,654
  • 3
  • 26
  • 22
  • 1
    Link to what -m does: https://stackoverflow.com/questions/7610001/what-is-the-purpose-of-the-m-switch – Casebash Jan 09 '18 at 07:23
7

Run this command:

sudo chown -R $USER /Library/Python/2.7
McGrady
  • 10,869
  • 13
  • 47
  • 69
  • 1
    Doesn't this mess up the permissions with homebrew (for updates) or other system tools since the owner of this directory is `root`? – Javad Aug 08 '17 at 22:16
0

Use for Python V3+

sudo -H python -m pip install pylint

then simply check the version via

pylint --version 

should output something like

pylint 2.6.2
astroid 2.4.2
Python 3.9.1 (default, Feb  1 2021, 12:12:57) 
[Clang 12.0.0 (clang-1200.0.32.29)]