1

This is identical to this question, but the title is incorrect. And, the symptoms are more odious than explained in this post.

From a Ubuntu 14.04 upgrade to 16.04 -- Pip shows packages installed whilst in an active virtual environment even when the venv is deactivated.

Furthermore, when installing a package pip throws this error:

The directory '/home/user/.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/user/.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.  

I also get a permissions error when doing pip install <package_name> I can get around this with pip install --user <package_name>. And, sudo will only work as above with the -H option.

Any insights or a possible fix on this error would be great! Thanks in advance!

Ed

edlee
  • 189
  • 1
  • 12

1 Answers1

0

I found the answer to the issue. It occurs because the Virtualenv is installed with sudo and the pip/.cache file is owned by the user. There some packages will require access to sudo. Below is the info on the issue and reference. I have added a idiots guide below the explanation to this error.

  1. When globally installed packages are on the python path, and they conflict with the installation requirements, they are ignored, and not uninstalled.
  2. When globally installed packages are on the python path, and they satisfy the installation requirements, pip does nothing, and reports that requirement is satisfied (similar to how global packages can satisfy requirements when installing packages in a --system-site-packages virtualenv).
  3. pip will not perform a --user install in a --no-site-packages virtualenv (i.e. the default kind of virtualenv), due to the user site not being on the python path. The installation would be pointless.
  4. In a --system-site-packages virtualenv, pip will not install a package that conflicts with a package in the virtualenv site-packages. The --user installation would lack sys.path precedence and be pointless.

More info can be read here https://pip.pypa.io/en/stable/user_guide/#user-installs.

My Fix

  1. Removed all project packages in ~/user/.cache . Which where installed 'wrongly' pip uninstall -r <path_to_project_requirements.txt> (N.B. prefix with sudo when required).

  2. Removed virtualenv sudo pip uninstall virtualenv

  3. Install virtualenv using: pip --user install virtualenv. Which will stop the ownership issues. And, save you from having to install it globally with sudo -- you could also use the virtualenv wrapper which would probably save you some of this pain, but i'm not...

  4. Create your project directory: mkdir <project> and go into it cd project.

  5. virtualenv venv create your local environment folder to install your packages into . venv/bin/activate

  6. continue installation of your project requirements.

edlee
  • 189
  • 1
  • 12