8

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
8-Bit Borges
  • 9,643
  • 29
  • 101
  • 198
  • Possible duplicate of [Where is pip installed to when using get-pip.py?](http://stackoverflow.com/questions/22278138/where-is-pip-installed-to-when-using-get-pip-py) – Loaf Jan 08 '17 at 02:57
  • not a duplicate. `pip` is on my `path`. `sudo pip` isn't. – 8-Bit Borges Jan 08 '17 at 03:06
  • duplicate of: [Command not found when using sudo](http://stackoverflow.com/questions/12996397/command-not-found-when-using-sudo) – Omid Jan 19 '17 at 14:41

7 Answers7

9

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.

Jeff Tsay
  • 458
  • 6
  • 7
8

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 ...
Community
  • 1
  • 1
Tim Ludwinski
  • 2,704
  • 30
  • 34
0

You tried just doing sudo su and seeing if it works?

Furrowed
  • 53
  • 8
  • it gives me: `sh-3.2# ` – 8-Bit Borges Jan 08 '17 at 03:00
  • Yes, now you are root. Try running "pip install package" now. The sudo command is just a command to make you temporarily root. sudo su logs you in as root. – Furrowed Jan 08 '17 at 03:07
  • The only thing I can think of is that your root account has a different set of paths to your lower user account. Do you have a custom .bashrc? – Furrowed Jan 08 '17 at 07:33
  • I have, but not doing much. how could it help me? – 8-Bit Borges Jan 08 '17 at 18:24
  • Well, if you have a PATH set in that file, it could be why only that account finds it. I was going to comment on someone else's answer but don't have enough reputation yet so I'll comment here. run "which pip" in the terminal. This should tell you where it is located. Then do "sudo ". If you want a one liner to do all that, this should do it - "sudo `which pip`" <-- note the backticks, they must be in place for this to work. Obviously remove the quotation marks though. edit - The post formatting here strips the backticks out. They are around the whereis pip command – Furrowed Jan 09 '17 at 10:05
0

Wherever pip lives, it's not in your path when you sudo. So try this:

sudo /usr/local/bin/pip 

If that doesn't work, then say which pip to find out where pip lives, and proceed accordingly.

Alex L
  • 1,114
  • 8
  • 11
0

It seems like pip is not installed at system level. You can install pip at system level by running sudo apt-get install python-pip from terminal.After this you can upgrade pip by running sudo pip install --upgrade pip .

toanant
  • 331
  • 3
  • 9
0

If you use sudo env "PATH=$PATH" pip install xxx, you should be able to run the right pip executable.

-1

Have you tried

sudo -H <your_commands>

?

This should preserve your user environment.

Martin Krämer
  • 567
  • 3
  • 17