139

How can I use pip in oh-my-zsh? I was trying to install nltk through pip, but it told me zsh: command not found: pip. When I check plugins under .oh-my-zsh/custom/plugins, there is a folder named pip. I don't know what the problem is.

Edit:

$ echo $PATH
/home/xxx/bin:/usr/local/bin:/home/xxx/bin:/home/xxx/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

$ type pip
pip is an alias for noglob pip
GabLeRoux
  • 16,715
  • 16
  • 63
  • 81
Gejun
  • 4,012
  • 4
  • 17
  • 22

11 Answers11

287

Maybe you have installed both python2 and python3. python3 may have been installed later.

You may try to use pip3 instead of pip.

First, input the command:

pip3 -V

If you see the version, the pip3 can be used.

Then you can input command line to install nltk:

pip3 install nltk

I got a way to help you use pip in zsh. We can use nano to edit files. In nano, ctrl+X to save and exit

In the ~ directory, input the command:

nano .bash_profile

You may see some codes like:

# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH

Copy them and paste them to the end of .zshrc file by using command:

nano .zshrc

Then input the command:

pip -V

If you see the version, pip can be used.

GabLeRoux
  • 16,715
  • 16
  • 63
  • 81
Leon Xiong
  • 3,563
  • 1
  • 13
  • 8
51

In case you do

which pip

and it doesn't show the path, just do

which pip3

This will print the path which is /usr/local/bin/pip3 Then do open ~/.zshrc or nano ~/.bash_profile.

Make alias for pip like:

alias pip=/usr/local/bin/pip3

N.B: You copy that line above and paste in your .zshrc file.

After do source ~/.zshrc and close .zshrc

  • Note: You can also run this command line to copy to your `.zshrc` file ```echo "alias python=/usr/bin/pip3" >> ~/.zshrc``` Then restart your terminal – Michael Le Aug 04 '23 at 16:52
22

For me it's working to do

python -m pip install [package_name]

instead of

pip install [package_name]
xhenryx14
  • 704
  • 6
  • 10
  • You can add an alias to your shell if you update` ~/.zshrc` file. Something like `alias pip=/usr/local/bin/pip3` That will then allow you to run the pip command directly without calling python first – JackDev Jun 16 '23 at 14:23
21

So you are using oh-my-zsh framework for zsh or Z shell. First, try the command:

pip3 -V

If you get something like this below, that means you have the pip3 package already and must be having python3 as well.

pip 22.0.4 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)

Then edit your .zprofile instead of .bashprofile as you are using zsh. This is the command.

nano ~/.zprofile

Then it should have the two alias like this.

# Setting PATH for Python 3.10
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}"
export PATH

alias python=python3
alias pip=pip3

Make sure you save it. Exit and Re-open you terminal. Type the command:

pip -V

It should have the same result as the pip3 -V like this:

❯ pip -V
pip 22.0.4 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)

Then you can use pip or pip3 interchangeably for installing your nltk package like this.

pip install nltk
toking
  • 320
  • 2
  • 10
19

If you installed python3.x, you should run with pip3(not pip)

11

I'm on MacOS and use ZSH. It seems pip 2.7 can't be found, although it is installed. I believe my paths to "pip" are linked wrong (I also have python3 and pip3 installed via brew).

To get around the issue I created an alias. If you don't have an .aliases file, create one in your homedir. Then open the file:

nano ~/.aliases

and add:

## PIP for python2.7 ##
alias pip="python -m pip "

You need to tell ZSH to pick up the alias file (assuming you don't have this setup already). Open your .zshrc:

nano ~/.zshrc

The add the following near the bottom of the file:

[ -f "$HOME/.aliases" ] && source "$HOME/.aliases"

From the terminal, run:

source ~/.zshrc

Or quit your terminal and reopen it.

Now you can run:

pip install <command>
elvis2
  • 111
  • 1
  • 3
  • 2
    I just added this alias to my .zshrc file: "alias pip3="python3 -m pip"". Why did you separate out the aliases into a separate file? – m0nsoon Oct 19 '20 at 18:25
8

Edit your rc file:

vim ~/.zshrc

Find the config plugins and delete the pip entry.

In a new terminal:

which pip

This will show you the real path of pip

GabLeRoux
  • 16,715
  • 16
  • 63
  • 81
likaiguo.happy
  • 2,138
  • 1
  • 15
  • 9
3

If you're running into this issue, it probably is due to versioning complications. Python 2 versus Python 3 on your OS may be resolving unexpectedly. Below is a quick workaround to get you to functioning behavior.

Try using the below for Python 2: python -m pip install <command>

Try using the below for Python 3: pip3 install <command>

Chioke Aarhus
  • 333
  • 3
  • 10
  • They key here is using pip3 command especially if you have installed Python 3. It worked for me after hours of online searching, thanks Chioke. – Bamanyi Dec 26 '20 at 20:00
1

In my case my OS was Ubuntu 20.04 and the pip doesn't come with python.

So, i've installed pip through the command

sudo apt install python3-pip

and I'm done.

To ensure run pip -V or pip3 -V

sh6210
  • 4,190
  • 1
  • 37
  • 27
0

My pip script is missing for some reason, so I have to install it.

$ python -m ensurepip --upgrade

More methods can be found here:pip installation

wj2061
  • 6,778
  • 3
  • 36
  • 62
0

You should consider upgrading.

Enter this in your terminal

/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 -m pip install --upgrade pip

and then...

Type: pip -V

erwin
  • 99
  • 2
  • 9