2

I'm running Ubuntu 15.10. I installed Pyhon 2.7 through aptitude:

sudo apt-get install python

now I'm trying to install pip using this guide. I downloaded get-pip.py, then I tried:

sudo python get-pip.py

Installation worked fine, but I got these annoying warnings:

The directory '/home/administrator/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/administrator/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

So I uninstalled all by the following command:

sudo python -m pip uninstall pip setuptools

And I tried a new installation without sudo:

python get-pip.py

but I got the following error:

OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pip'

How can I install pip (and wheels) in a proper way with caching enabled?

5

First, Python 2.7 is pre-installed on every currently supported Ubuntu release already. So you would not have had to install it first. That's why apt-get has told you that python is already in the newest version.

Second, you should usually prefer the Python modules packaged for apt from the repositories over those you get with pip from PyPI, unless you rely on the features or bug fixes of the latest version. The repository versions are often more or less outdated, but proofed to be compatible with whatever other package that is requiring them.

So to install pip for Python 2, run this:

sudo apt-get install python-pip

In case this old pip version is not working for your needs, you can later simply get the latest version (without uninstalling the old one!) using this command:

sudo -H pip install --upgrade pip

Another tip for you:
You should learn about and use virtualenvs, virtual python environments. You can install Python modules in a viertualenv only without affecting other virtualenvs or the system. It's the safest way to prevent version incompatibilities and messing around with packages needed by the system and other programs.

9
  • Hi! When I typed python before installation I got an error (I don't remember a message by apt-get similar to what you have just cited). It seemed that python interpreter was not present. After sudo apt-get install python all worked fine... According to you do not I need to uninstall python (installed by sudo apt-get install python)? So if I install pip through apt-get and later I upgrade, I get the same version of pip that I would have got through pip? Thanks a lot! – floatingpurr Mar 11 '16 at 0:38
  • 4
    Never do sudo apt-get remove python!!! Although you say that python wasn't installed before, this almost can't be true without having caused severe malfunctions of many programs. You are not supposed to remove neither the python package (Python 2.7) nor the python3 package (Python 3.4). – Byte Commander Mar 11 '16 at 7:14
  • 1
  • 1
    Very strange... o.O – Byte Commander Mar 11 '16 at 12:25
  • 3
    sudo -H runs the command as root, but sets the used home directory to root's home directory /root instead of the user's home directory /home/YOUR_USERNAMEas normal sudo would do. The warning is generated by pip because it does not want to generate cache files in your home directory as root which you yourself could not access as normal user. – Byte Commander Mar 11 '16 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.