Pip: IOError: [Errno 13] Permission denied: '/usr/local/bin/pip'

Created on 17 Dec 2016  ·  16Comments  ·  Source: pypa/pip

Description:

How can i solve the following problem:

I was trying to install autograd and scikit-learn, both through pip command. However, both installation failed, with the error
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pip'

thus i guess these error may caused by pip, so i test pip with update command 'pip install -U pip ', it replied
IOError: [Errno 13] Permission denied: '/usr/local/bin/pip'

I guess pip on my machine is broken? Any advice is pretty appreciate, thanks.

What I've run:

The log of running command 'pip install -U pip' listed below:

Downloading/unpacking pip from https://pypi.python.org/packages/b6/ac/7015eb97dc749283ffdec1c3a88ddb8ae03b8fad0f0e611408f196358da3/pip-9.0.1-py2.py3-none-any.whl#md5=297dbd16ef53bcef0447d245815f5144
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB): 1.3MB downloaded
Installing collected packages: pip
  Found existing installation: pip 1.5.4
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, owned by OS
  Can't roll back pip; was not uninstalled
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1436, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 672, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 902, in move_wheel_files
    pycompile=self.pycompile,
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 312, in move_wheel_files
    generated.extend(maker.make(spec))
  File "/usr/share/python-wheels/distlib-0.1.8-py2.py3-none-any.whl/distlib/scripts.py", line 311, in make
    self._make_script(entry, filenames, options=options)
  File "/usr/share/python-wheels/distlib-0.1.8-py2.py3-none-any.whl/distlib/scripts.py", line 215, in _make_script
    self._write_script(scriptnames, shebang, script, filenames, ext)
  File "/usr/share/python-wheels/distlib-0.1.8-py2.py3-none-any.whl/distlib/scripts.py", line 195, in _write_script
    self._fileop.write_binary_file(outname, script_bytes)
  File "/usr/share/python-wheels/distlib-0.1.8-py2.py3-none-any.whl/distlib/util.py", line 384, in write_binary_file
    with open(path, 'wb') as f:
IOError: [Errno 13] Permission denied: '/usr/local/bin/pip'

Storing debug log for failure in /home/eric/.pip/pip.log

support

Most helpful comment

You should add the --user option to install without needing root permission.

All 16 comments

You should add the --user option to install without needing root permission.

Couldn't we add some helpful message for a user? E.g. something like: "if you don't have root permissions, use virtualenv instead?"

E.g. in R-lang you get this:

> install.packages('yaml')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages("yaml") :
  'lib = "/usr/local/lib/R/site-library"' is not writable
Would you like to use a personal library instead?  (y/n) y
Would you like to create a personal library
~/R/x86_64-pc-linux-gnu-library/3.0
to install packages into?  (y/n) y

that would definitely help a lot of beginners...

@hnykda I've made a PR for improving the error message when this happens (that I should have made a while back) - #4233.

Thanks. I like that.

go to super user. after that run 'pip install -U pip'

Closing as there is nothing we can do.
Hopefully #4233 will help reduce the confusion.

add --userworks! I have tried.

What will be the command by adding add --user?

pip install --user <package you want to install>

Also see: https://pip.pypa.io/en/stable/reference/pip_install/#cmdoption-user

Thanks urllib3 installed successfully using pip.

yes, --user works :)

Still working! Thanks
pip3 install --user .

I have my python script which is retrieving url data and writing to file using below command . When I am running this script on my local machine, it works but running through jenkins gives me error 13.

response = urllib.urlopen(url)
tmpXml = response.read()
with open (/tmp/tempxml1.txt,'wr') as file1:
file1.write(tmpXml)
response.close()

Error displayed on jenkins -
IOError: [Errono 13] Permission denied: '/tmp/tempxml1.txt'

Any mastermind here to help me out

@WV-no7 : please don't advise people to use sudo pip, it's very bad practice.

the python get-pip.py --user command works with Ubuntu 18.04. Will this continue to be an issue for those who don't update python to the latest version? It appears Python 2.7 will be deprecated in 2020..

You should add the --user option to install without needing root permission.

Was this page helpful?
0 / 5 - 0 ratings