Pip error after changing from bash to zsh
I saw this error message and it was an issue related to my $PATH
.
Here's some troubleshooting steps.
You can view your path with echo $PATH
.
which pip
and which python
should return the same location. Those commands search the directories in your $PATH
to find the first location that contains the executable.
If you're using pyenv
, which pip
and which python
will return the same "shims" directory but that doesn't necessarily mean the executables are being run from the same directory. In that case, use pyenv which pip
and pyenv which python
.
In my case, my $PATH had a ~/.local/bin/
directory that was being prepended when I ran inside tmux. ~/.local/bin/
had a pip
executable but no python
executable. So I was trying to use a pyenv
version of Python but a ~/.local/bin/pip
version of pip.
edit to clarify:
If which pip
and which python
show different paths, or in the case of pyenv if pyenv which pip
and pyenv which python
show different paths, then that may be the problem.
The solution will depend on your environment so it's difficult to give a one-solution-fits-all answer.
Maybe your $PATH
has ~/.local/bin
before /usr/bin
and ~/.local/bin
has a pip
executable but not a python
executable. So your computer is finding pip
in ~/.local/bin
but finding python
in /usr/bin
. In that case, you could delete the pip
in ~/.local/bin
if you don't need it. Or you could update it to be a symlink to the pip in /usr/bin
(assuming you have another pip
executable there). Or you could add a symlink of ~/.local/bin/python
to /usr/bin/python
. Or you could update your $PATH
so that it searches /usr/bin
before searching ~/.local/bin
.
The solution is dependent on your environment, how you installed Python, which version you want to use, etc...
Related videos on Youtube
MarvinKweyu
"Everybody stand back, I know regular expressions!" ─ xkcd 208
Updated on September 18, 2022Comments
-
MarvinKweyu over 1 year
So I recently changed from the
bash
shell tozsh
. However, I have some trouble when working withpython
specifically pip. When I trypip list ModuleNotFoundError: No module named 'pip._internal.main'
Doing
which pip
gives me/home/marvin/.local/bin/pip
, So following a line I saw in mybashrc
, I added this tozshrc
# adding packages installed via pip export PATH="/home/marvin/.local/bin:$PATH"
I also restarted shell and machine just to give a try. I am still not able to work with virtual environments with pip. Could someone guide me on a solution to this?
[Edit]
So I did
python3 -m pip install --user --upgrade pip
and got it working globally. Unfortunately, I had to re-create my virtual environment. The hiccup though, switching between shells would mean a re-creation of an environment. there's gotta be a better way of doing this
-
Kusalananda over 4 yearsDid you have some other
pip
or Python-related settings in your oldbash
init files tah may be relevant to howpip
behaved underbash
?
-
-
MarvinKweyu over 4 yearsTried that out, would not work on zsh as it does not recognize pip. Definitely works in bash. Check the updated question?
-
MarvinKweyu over 4 yearsI got a
/home/marvin/.local/bin/pip
and a/bin/python
forpyenv which ...
-
Eric Ihli over 4 yearsEdited to clarify. In short: that they are different is what I think is the problem. Try doing whatever it takes to make those match and see if it fixes the issue. It's not easy for someone to say what you should do to make those match because it's very dependent on your particular environment.