3

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?

1 Answers1

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.

Byte Commander
  • 107,489
  • 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 00:38
  • ...anyway do you think that using aptitude will fix my problem? I thinked that my problem was related to permission on folders... – floatingpurr Mar 11 '16 at 01:15
  • 5
    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 07:14
  • Got it! Could be a good a idea create a virtualenv with its own python interpreter and its packages to create a dedicated/isolated development environment? – floatingpurr Mar 11 '16 at 10:31
  • 1
    http://askubuntu.com/questions/244641/how-to-set-up-and-use-a-virtual-python-environment-in-ubuntu – Byte Commander Mar 11 '16 at 10:37
  • To complete my comments, when I typed python for the very first time, I got: `The program 'python' can be found in the following packages:
    • python-minimal
    • python3

    Try: sudo apt-get install ` That's the reason why I installed an interpreter : )

    – floatingpurr Mar 11 '16 at 11:41
  • 1
    Very strange... o.O – Byte Commander Mar 11 '16 at 12:25
  • Yep... : / Last question: why does sudo -H fix permissions problems on directories like /home/administrator/.cache/... – floatingpurr Mar 11 '16 at 12:43
  • 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