Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sudo and pip not on the same path

Tags:

python

path

sudo

pip and sudo are not on the same path on my machine, so when (basically all the time) I need to run both commands, like so:

sudo pip install xxx

I get:

sudo: pip: command not found

pip downloads packages, but since access is being denied at the end of installation, it ends up failing.

by doing pip -V, (which pip returns nothing) I get to know where pip is:

pip 1.5.4 from /Library/Python/2.7/site-packages/pip-1.5.4-py2.7.egg (python 2.7)

and by doing sudo bash -c 'echo $PATH',

I get:

/usr/bin:~/bin:/bin:/usr/local/bin:/usr/local/sbin:/Applications/Zed.app/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin

I have tried to symlink pip into sudo's directories, like so:

$ sudo ln -s /usr/local/bin/pip /usr/bin/pip, to no avail.

How do I put sudo on the same path?

like image 256
8-Bit Borges Avatar asked Jan 08 '17 02:01

8-Bit Borges


People also ask

How do I fix sudo pip command not found?

A “pip: command not found” error occurs when you fail to properly install the package installer for Python (pip) needed to run Python on your computer. To fix it, you will either need to re-install Python and check the box to add Python to your PATH or install pip on your command line.

Should you run pip with sudo?

Never ever ever ever use pip or pip3 with sudo . Use pip --user or Python virtual environments instead.


2 Answers

According to here: https://unix.stackexchange.com/a/83194, you should be able to run this command like this:

sudo env 'PATH=$PATH:/usr/local/bin' pip ...
like image 104
Tim Ludwinski Avatar answered Nov 04 '22 06:11

Tim Ludwinski


After installing pip, I did

sudo ln -s /usr/local/bin/pip /usr/bin/pip

and now root can use pip without any PATH modifications. I had trouble making PATH modifications to the root account.

like image 21
Jeff Tsay Avatar answered Nov 04 '22 07:11

Jeff Tsay