Using sudo with pip3?

cs at zip.com.au cs at zip.com.au
Fri Jan 6 17:36:44 EST 2017


On 06Jan2017 15:44, jim <jf_byrnes at comcast.net> wrote:
>Setting up a new computer to run Ubuntu 16.04. Started using pip3 to 
>install all the python stuff I had on the old machine and got this 
>message:
>
>jfb at jims-1604:~$ sudo pip3 install matplotlib
>[sudo] password for jfb:
>The directory '/home/jfb/.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.
>
>I (jfb) own the directory in question.
>
>I used sudo because I recall needing to use it on the old machine to 
>get something to install. So is it necessary or even desirable to use sudo 
>with pip3?

I would not, unless I were specificly trying to install into the system's 
python3 libraries. That will inherently fight with any vendor (Unbuntu) 
supplied packages that come through apt-get.

Instead I would make myself a virtualenv _based off the system python3_ and use 
the venv's pip to install extra packages. Not using sudo. They will land in 
your virtualenv directory's lib area, be entirely owned and controlled by you, 
and not have any complications that come with sudo.

Then just symlink the virtualenv's "python3" into your own $HOME/bin and 
whenever you invoke "python3" it will run the virtualenv one, getting all the 
package goodness you have added.

An important sysadmin rule of thumb: use apt (or yum etc, depending on distro) 
as root to install vendor supplied packages. And install your owon packages _as 
you_ in another area, _not_ in the system managed area. Virtualenv makes this 
very easy to do for Python.

Cheers,
Cameron Simpson <cs at zip.com.au>



More information about the Python-list mailing list