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

But software get installed. I just want to know what the heck above error means.

For example:-

 When I tried to install pandas, it goes like this..

  • 1
    The error means exactly what it says. – user692175 Jan 3 '18 at 6:13

When you run sudo your environment is passed along while the effective user switches to root. Your environment includes that your ~/ or home directory (the value of the environment variable HOME) is /home/bijay.

pip looks for an http cache before downloading packages. Probably for a combination of security, sanity and privacy reasons pip disables the cache so as not to write to a cache directory not owned by the current user. It's just telling you that it did that.

As it hints, using sudo -H would set the HOME environment variable before executing the command passed to sudo, using root's home directory /root as $HOME instead of your user's. The cache could then be written in /root/.cache/pip/http with no errors.

As a sidenote, you probably shouldn't be running pip as root anyway.

  • 1
    Thanks. It pretty much explains. But why running pip as root is not good. Isn't pip just a package manager to install python software/libraries ? – Bijay uprety Jan 3 '18 at 6:30
  • @Bijayuprety see askubuntu.com/questions/802544/… – Zanna Jan 3 '18 at 6:39
  • Generally speaking if you want system-wide python packages use your distributions packages instead. – jdwolf Jan 3 '18 at 6:47
  • 2
    If you want to install without using root or sudo, simply use the --no-cache-dir argument. The only downside is that it may take a little longer and might use slightly more of your network bandwidth. – cowlinator Jan 18 '20 at 3:05
  • @cowlinator Or you could just ignore the warning because its already disabling the cache. However the warning also tells you what you need to do. If pip didn't need root then it'd use the users cache without disabling it. – jdwolf Jan 19 '20 at 0:54

This worked for me:

$ sudo chown -R root /home/$USERNAME/.cache/pip/
$ sudo chown -R root /home/$USERNAME/.cache/pip/http/

Note: Use this way only if you always use pip as root. Otherwise pip may not use the cache directories since they are owned by root.

  • Using pip as root is highly discouraged as it can really mess up an OS. – nealmcb Jul 26 '19 at 1:29
  • @nealmcb why not provide an answer then? – samayo Dec 6 '19 at 1:44
  • @samayo The answer and comments by jdwolf already address the sudo issue, including the handy link to askubuntu.com/questions/802544/… – nealmcb Dec 7 '19 at 2:33

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.