pip exists, says no module named pip - python

I have pip installed and can clearly see the file (by using which pip) but, when I go to actually run a command like pip install -r requirements.txt (or even just pip to get help), I get the following error:
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip._internal import main
ModuleNotFoundError: No module named 'pip'
I get this whether I'm using pip 2 or 3. What is going on here? Any way to fix it without reinstalling the whole thing?

Force a reinstall by running
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall

Try this command
python -m pip <action>

Succinct answer - I ran pip -m site to see where my site packages are, and poked around in there and couldn't find pip. It must have gotten deleted...
This makes me wonder, though, why did pip disappear when I ran pip install --upgrade pip as it instructed me to do! 🤔

Related

How to turn Selenium Python Program into .exe with Pyinstaller? (Proper Way) [duplicate]

I work on Ubuntu 14. I install python3 and pip3.
When I try to use pip3, I have this error
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 70, i
n <module>
import packaging.version
ImportError: No module named 'packaging'
Does someone know what is the issue?
Many thanks
First update your pip version itself. You can take a look at this answer
pip3 install --upgrade pip
And then try to install packaging, if its not already installed by now.
pip3 install packaging
I recently had the same error. Unfortunately none of the other answers solved my problem. Finally installing the following package resolved my issue:
sudo apt install python3-packaging
For older versions of Python you may need to adjust the command:
sudo apt install python-packaging
If I understand well, the issue that causes confusion in other's replies is that you have an error while running pip itself, which prevents self-updates of pip or installation of the missing package.
As requested, please state exactly how you installed Python 3 and pip. Ubuntu 14 does not come with Python 3.5.
For diagnosis, please give the output of
which python3
that is probably /usr/bin/python3 and refers to the system-wide python3 while your pip is located in /usr/local/bin/pip3.
Suggested solution: Uninstall system pip with apt-get remove python3-pip and try again with either pip3 or python3.5 -m pip.
I got this issue and I solved it by getting the path to my python module on my virtualenv
python3.7 -c 'import sys; print(sys.path)'
Then I cloned github repository for Packaging
in one of the directory..
That's about it
I tried all of the above.
I had to manually add the libraries to the pyinstaller command as data:
.\pyinstaller.exe -F --add-data ".\venv\Lib\site-packages\packaging;packaging" --add-data ".\venv\Lib\site-packages\webdriver_manager;webdriver_manager" --onefile .\departed_shipments.py

System PIP seems broken after I tried to upgrade it on my Big Sur / Apple silicon Macbook

It seems like I messed up the system pip by pip3 install --upgrade pip. Actually I even do not exactly remember whether I did upgrade or not.
Now when I try to use pip3, it gives an error like
Traceback (most recent call last):
File "/Applications/Xcode.app/Contents/Developer/usr/bin/pip3", line 6, in <module>
from pip._internal import main
ImportError: cannot import name 'main' from 'pip._internal' (unknown location)
I tried sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall to revert back PIP by this answer, but it fails.
/Applications/Xcode.app/Contents/Developer/usr/bin/python3: No module named pip.__main__; 'pip' is a package and cannot be directly executed
which pip3 gives /usr/bin/pip3
Now I am trying to revert back the system tools and use virtual environment.
What should I do? I can't even check which pip version is installed at the moment.
Thanks in advance.

pip3 not working on ubuntu 20.04: "has no attribute 'SourceFileLoader'"

On Ubuntu 20.04 i have installed pip3 with the following command:
sudo apt install python3-pip
But when I run pip3 I get the following error:
Traceback (most recent call last):
File "/usr/bin/pip3", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.8/dist-packages/pkg_resources.py", line 1479, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
In a virtual-environment the pip3 command works fine however.
As suggested in other SO answers I have tried reinstalling python3 and pip3, all without success. A lot of other answers use pip3 to solve the problem, but I'm unable to run pip3.
I have noticed that several other programs (docker-compose, Guake) give me a similar error.
I run python 3.8.2. And when I open an virtual-environment I can see that my pip3 version is 20.0.2.
I came a long way to fixing this, but in the end I went with a fresh install. I'll share here what I learned, hoping it can help somebody else.
My hypothesis is that it went wrong when I accidentaly installed a requirements.txt without being in an virtual environment. That triggered the installation of an old setuptools, which then broke pip and ruined everything.
Possible fix could be:
Remove pip: sudo apt-get --purge autoremove python3-pip
Install pip via python: python3.8 -m pip install --upgrade --force-reinstall pip. Now pip works again.
Now try to fix setuptools: pip install --upgrade --ignore-installed setuptools. Fix the issues that pop here (how? don't know). An issue I had here was that I was not allowed to call pip with sudo.
In the end I guess you'll want pip installed the normal way, so you uninstall python3.8 -m pip uninstall pip and install sudo apt install python3-pip
Next time I'll skip installing python3-pip completely. That way I'm forced to open a virtual environment.
In the end, several issues starting popping up (also because I tinkered around a lot) and I just lost faith in my installation. Even if I would fix it all, I knew that when the next issue would pop up I would again feel like this might be the problem. Better to start fresh and have a solid base.

Python pip3 throws ModuleNotFoundError: No module named 'pip'

I have both python 2 and 3 and pip 2 and 3 installed, and all had been working fine. I tried installing graph-tools (https://git.skewed.de/count0/graph-tool/wikis/installation-instructions) using port install py-graph-tool, and it seems to have messed with my installations.
Specifically, I can no longer install packages with pip3, e.g.:
$ pip3 install networkx
Traceback (most recent call last):
File "/Users/me/bin/pip3", line 8, in <module>
from pip import main
ModuleNotFoundError: No module named 'pip'
even though
$ which pip
/Users/me/bin/pip
$ which pip3
/Users/me/bin/pip3
Less immediately, I have had similar problems (I assume) with different Python installations interfering with each other... I have done some searching to better understand this problem, but anyone willing to explain the basics or point to some good explanations online, I would be grateful!
You can manually install pip3
wget https://bootstrap.pypa.io/get-pip.py
sudo python3.6 get-pip.py

No module named packaging

I work on Ubuntu 14. I install python3 and pip3.
When I try to use pip3, I have this error
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 70, i
n <module>
import packaging.version
ImportError: No module named 'packaging'
Does someone know what is the issue?
Many thanks
First update your pip version itself. You can take a look at this answer
pip3 install --upgrade pip
And then try to install packaging, if its not already installed by now.
pip3 install packaging
I recently had the same error. Unfortunately none of the other answers solved my problem. Finally installing the following package resolved my issue:
sudo apt install python3-packaging
For older versions of Python you may need to adjust the command:
sudo apt install python-packaging
If I understand well, the issue that causes confusion in other's replies is that you have an error while running pip itself, which prevents self-updates of pip or installation of the missing package.
As requested, please state exactly how you installed Python 3 and pip. Ubuntu 14 does not come with Python 3.5.
For diagnosis, please give the output of
which python3
that is probably /usr/bin/python3 and refers to the system-wide python3 while your pip is located in /usr/local/bin/pip3.
Suggested solution: Uninstall system pip with apt-get remove python3-pip and try again with either pip3 or python3.5 -m pip.
I got this issue and I solved it by getting the path to my python module on my virtualenv
python3.7 -c 'import sys; print(sys.path)'
Then I cloned github repository for Packaging
in one of the directory..
That's about it
I tried all of the above.
I had to manually add the libraries to the pyinstaller command as data:
.\pyinstaller.exe -F --add-data ".\venv\Lib\site-packages\packaging;packaging" --add-data ".\venv\Lib\site-packages\webdriver_manager;webdriver_manager" --onefile .\departed_shipments.py

Categories