When using sudo to run pip "pip: command not found" but it's installed

227,624

Solution 1

If you install pip from the Ubuntu repositories pip will work with sudo (I have used pip this way on 12.04 through to 14.04).

sudo apt-get install python-pip

Solution 2

Your pip is installed in /home/nyzlfc/.local/bin, which is not in the sudo path and with a good reason. Just add ~/.local/bin to your path and step away of sudo as it's unnecessary.

Solution 3

I had the same problem, and the reason I had this problem (on Debian) is that I installed python3.2 and python3-pip and as such, I really didn't have a pip executable, I also didn't have a pip3 executable. I have pip-3.2 executable.

As such I would also recommend doing:

sudo pip

and then pressing the tab to see the autocomplete options.

Solution 4

First check your $PATH variable using the echo command:

$ echo $PATH

If /usr/local/bin is missing, edit the hidden file .profile, located in your home directory. If this file is missing, edit .bash_profile instead.

Add as very last PATH statement the following line:

PATH=$PATH:/usr/local/bin

Solution 5

Instead of doing pip install <package name>

Try pip3 install <package name>

Share:
227,624

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    sudo easy_install pip

    Searching for pip
    Best match: pip 1.4.1
    Processing pip-1.4.1-py2.7.egg
    pip 1.4.1 is already the active version in easy-install.pth
    Installing pip script to /home/nyzlfc/.local/bin
    Installing pip-2.7 script to /home/nyzlfc/.local/bin
    Using /home/nyzlfc/.local/lib/python2.7/site-packages/pip-1.4.1-py2.7.egg
    Processing dependencies for pip
    Finished processing dependencies for pip
    

    And then when I run

    sudo pip install -U pyyaml nltk
    

    I get:

    sudo: pip: command not found
    
  • lazyPower
    lazyPower about 10 years
    You dont always need to use sudo to install python modules. you can scope them to your user using pip install --user ipdb (for example) - from there, they are installed to ~/.local/lib/python-ver/ and the bins are placed in ~/.local/bin/ so add ~/.local/bin to your $PATH and you're g2g with non-sudo use of pip.
  • NGRhodes
    NGRhodes about 10 years
    Good point, I was working on the fact the question was using sudo, that installing with sudo was desired. I generally do as my code is used by different users on the same system
  • Almir Campos
    Almir Campos over 6 years
    +1 sudo pip and then pressing tab to see the autocomplete options... did the job for me.
  • Conjecture
    Conjecture almost 4 years
    This is not working for me, Ubuntu 20.0.4
  • Ng Sek Long
    Ng Sek Long over 3 years
    20.04 use this sudo apt install python3-pip, then use pip3 install xxx to install your packages
  • Dinesh Singh
    Dinesh Singh almost 3 years
    You saved my day. Thanks a ton for the answer