I have python2 and python3 both installed on Ubuntu 16.04, and use python3 primarily. I have both pip and python aliased to pip3 and python3, respectively, in my user's .bashrc.

However, I had always gotten funky interactions with pip while installing new packages, and now I find out why: when I sudo pip install whatever, the alias in .bashrc is no longer applied to the superuser.

Supposing this computer isn't mine alone and other users might log in and want to use python2 primarily, how can I set it up so that for my user only can use sudo pip to install python3 packages?


sudo resets environment with secure path, so you don't get user environments when using sudo command. You can use sudo python3 -m ModuleName to run a module with python3, for example

arryph@localhost:~$ sudo python3 -m pip --version
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.