Ubuntu – Permission denied when trying to run pip install ipython

ipythonpermissionspippythonsoftware installation

When I used

pip install ipython

or

pip install "ipython[notebook]"

I get the following error:

Downloading/unpacking ipython
  Downloading ipython-2.3.1-py27-none-any.whl (2.8MB): 2.8MB downloaded
Installing collected packages: ipython
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 1435, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 671, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 901, in move_wheel_files
    pycompile=self.pycompile,
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 206, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 193, in clobber
    os.makedirs(destsubdir)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/IPython'

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

What does this error mean? How do I fix it?

Best Answer

You can have both the default version of IPython from the default Ubuntu repositories and IPython 2.3.1 installed at the same time.

  1. Install IPython from the default Ubuntu repositories using the following command:

     sudo apt-get install ipython ipython3 # ipython is available in 18.04 and earlier
    
  2. Install IPython 2.3.1 in a virtual environment. virtualenv allows you to create a sandboxed and isolated environment where Python packages can be installed without interfering with other packages on the same machine. Install Python virtual environment creator (virtualenv):

     sudo apt-get install python-virtualenv virtualenv 
    

    Set up a virtual environment for Python (Information about virtualenv basic usage), activate your Python virtual environment from the terminal, and then install the current version of IPython using pip install.

     pip install --user ipython 
    

This is working on my Ubuntu 14.04 using IPython from the default Ubuntu repositories and IPython 2.3.0 installed inside a Python virtual environment (virtualenv).