pip: no module named _internal
PythonPipPython Problem Overview
I have a problem when I try to use pip in any way. I'm using Ubuntu 16.04.4
I should say that I've used it already, and I never had any problem, but starting today when I use any command I always get the same error (as an example using pip --upgrade
).
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named _internal
I have tried doing sudo apt-get remove python-pip
followed by sudo apt-get install python-pip
but nothing changed.
Python Solutions
Solution 1 - Python
This did it for me:
python -m pip install --upgrade pip
Environment: OSX && Python installed via brew
Solution 2 - Python
An answer from askUbuntu works.
For pip2.7, you can at first curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
, then python2.7 get-pip.py --force-reinstall
to reinstall pip.
Problem solved. Also works for python3.
Solution 3 - Python
This solution works for me:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
or use sudo for elevated permissions (sudo python3 get-pip.py --force-reinstall
).
Of course, you can also use python
instead of python3
;)
Solution 4 - Python
Are you using python 2 or python 3? The following commands could be different!
- run
python3 -m pip --version
to see if you have pip installed. - if yes, run
python3 -m pip install --upgrade pip
. - if no, run
sudo apt-get install python3-pip
, and do it again.
Solution 5 - Python
Refer to this issue list
sudo easy_install pip
works for me under Mac OS
For python3
, may try sudo easy_install-3.x pip
depends on the python 3.x version. Or python3 -m pip install --user --upgrade pip
Solution 6 - Python
In file "/usr/local/bin/pip" change from pip._internal import main
to from pip import main
Solution 7 - Python
This issue maybe due to common user do not have privilege to access packages py file.
-
root user can run 'pip list'
-
other common user cannot run 'pip list'
[~]$ pip list Traceback (most recent call last): File "/usr/bin/pip", line 7, in
from pip._internal import main ImportError: No module named pip._internal
Check pip py file privilege.
[root@]# ll /usr/lib/python2.7/site-packages/pip/
合計 24
-rw------- 1 root root 24 6月 7 16:57 __init__.py
-rw------- 1 root root 163 6月 7 16:57 __init__.pyc
-rw------- 1 root root 629 6月 7 16:57 __main__.py
-rw------- 1 root root 510 6月 7 16:57 __main__.pyc
drwx------ 8 root root 4096 6月 7 16:57 _internal
drwx------ 18 root root 4096 6月 7 16:57 _vendor
solution : root user login and run
chmod -R 755 /usr/lib/python2.7
fix this issue.
Solution 8 - Python
For completeness, I just encountered this problem with "Ubuntu latest" ... v18.04 ... and fixed it in this way:
python3 -m pip install --upgrade pip
(Notice that it was necessary to specify python3
since this references Python 3.6.9. The python
command on the same system references Python 2.7.17. Since this is apparently a system-wide installation it encountered a ["not sudo" ...] permission error, but it didn't matter because it was the wrong thing to do anyway. I was encountering the problem with pip3
.)
Solution 9 - Python
I've seen this issue when PYTHONPATH
was set to include the built-in site-packages
directory. Since Python looks there automatically it is unnecessary and can be removed.
Solution 10 - Python
I just encountered the same problem and in my case, it turns out this is a conflict between the python installation in my virtualenv and the site-wide python (Ubuntu). What solves it for me is to run pip in this way, to force usage of the correct python installation (in my vortualenv):
python3 -m pip install PACKAGE
instead of
pip3 install PACKAGE
I realised this when I tried to follow some of the answers here that suggest re-installing pip and the error output I got was pointing to an existing site-wide python library path although I had activated my virtualenv. Worth trying before deleting and re-installing stuff.
Solution 11 - Python
Solution 12 - Python
Its probably due to a version conflict, try to run this, it will remove the older pip somehow.
sudo apt remove python pip
Solution 13 - Python
I have fixed this error by running the following commands:
sudo apt remove python-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
It will remove the previously installed pip and reinstall it. Thanks :)
Solution 14 - Python
Nothing worked for me, but only one thing: I used sudo in front of the command and it is working fine.
Solution 15 - Python
I tried the following command to solve the issue and it worked for me:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Solution 16 - Python
The following solution solved the problem on my machine for python2.7 "$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py" and then "$ sudo python2.7 get-pip.py --force-reinstall"
Solution 17 - Python
For the current user only:
easy_install --user pip
or
python -m pip install --upgrade --user pip
The second may give /usr/bin/python: No module named pip
Even if which pip
finds the module named pip.
In this case try the easy_install
Solution 18 - Python
I met the same error on Windows when I tried to install a package via pip3:
Traceback (most recent call last):
File "d:\anaconda\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\anaconda\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\Anaconda\Scripts\pip3.6.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip._internal'
My python is installed via Anaconda. I solved this issue by reinstalling pip via conda:
conda install pip
After that, pip returns to normal.
Solution 19 - Python
I have the same problem on my virtual environment after upgrade python installation from 3.6 to 3.7 but only on vent globally pip work fine, to solve it I deactivate and delete my virtual environment after recreate again and now is fine, on venv:
deactivate
rm -rvf venv
and after recreate the virtual environment. I use mac OS 10.11, and python 3
Solution 20 - Python
(On windows) not sure why this was happening but I had my PYTHONPATH setup to point to c:\python27 where python was installed. in combination with virtualenv this produced the mentioned bug.
resolved by removing the PYTHONPATH env var all together
Solution 21 - Python
my solution: first step like most other answer:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python2.7 get-pip.py --force-reinstall
second, add soft link
sudo ln -s /usr/local/bin/pip /usr/bin/pip
Solution 22 - Python
This command works for me.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py --force-reinstall --user
Solution 23 - Python
you can remove it first, and install again ,it will be ok. for centos:
yum remove python-pip
yum install python-pip
Solution 24 - Python
I fixed this problem by
sudo apt-get install python3-pip
this worked even for python2.7, amazing...
Solution 25 - Python
My solution is adding import pip
to the script linked to the pip/pip3
commands.
Firstly, open the file (e.g. /usr/local/bin/pip
) with your favorite text editor and the sudo mode. For example, I use sudo vim /usr/local/bin/pip
to open the script file.
You will obtain some file as following:
import re
import sys
from pip._internal import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Afterwards, insert the statement import pip
just before the from pip._internal import main
then the issue is resolved.
Solution 26 - Python
These often comes from using pip to "update" system installed pip, and/or having multiple pip installs under user. My solution was to clean out the multiple installed pips under user, reinstall pip repo, then "pip install --user pip" as above.
See: https://github.com/pypa/pip/issues/5599 for an official complete discussion and fixes for the problem.
Solution 27 - Python
windows OS:
1、download this file:“https://bootstrap.pypa.io/get-pip.py”,Put it in this(E:\PythonProject\venv\Scripts’(Your virtual environment installation directory)) directory!
2、open ‘Windows PowerShell’
3、cd ‘E:\PythonProject\venv\Scripts’(Your virtual environment installation directory)
4、run cmd ‘py get-pip.py’
Solution 28 - Python
Please verify the directory permission for /usr/local/lib/python3.9/ and modify the permission using chown command
sudo chown -R centos:centos /usr/local/lib/python3.9/
its helps me.