This question already has answers here:
ImportError: No module named pip
(31 answers)
Closed 10 months ago.
I can't use pip and I don't know why.
The error I get is shown below:
File "d:\python\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "d:\python\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "D:\Python\Scripts\pip.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'
If I try py -3.8 -m pip install I get
D:\Python\python.exe: No module named pip.
If I use get-pip nothing happens.
If I try to upgrade pip nothing happens.
Try
python -m ensurepip
This command activates pip.
Ref. https://docs.python.org/3/library/ensurepip.html
After this you can upgrade
python -m pip install --upgrade pip
I had the same problem. But in my case, when I was upgrading the pip version the new version stopped installing (upgrading) before the older version successfully uninstalled. After searching 4 or 5 sites I found:
python -m ensurepip
I was able to use the pip command and also this:
python -m pip install --upgrade pip
I don't know what OS you are using and what errors you got when using get-pip, but I had similar issue on Ubuntu20 and this solved it:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Credit: #Benjamin's answer here: https://askubuntu.com/questions/1025189/pip-is-not-working-importerror-no-module-named-pip-internal
For Debian/Ubuntu/Linux Mint and derivatives users
Install pip using APT:
sudo apt install python3-pip
Try this
python -m pip install --upgrade pip
A suggestion, try to use anaconda or virtual env to avoid such issues.
I had the same problem, but found that python -m ensurepip just told me that the pip scripts were already installed. So what I did was delete the 2 pip directories under C:\Users\[user_id]\AppData\Local\Programs\Python\Python38\Lib\site-packages, then run python -m ensurepip again. That fixed it for me.
Related
Running the following command gives me the following error:
pip install pygame
Error Stack:
Traceback (most recent call last):
File "C:\Python34\lib\runpy.py", line 171, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python34\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Python34\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Python34\lib\site-packages\pip\__init__.py", line 1, in <module>
from typing import List, Optional
ImportError: No module named 'typing'
Running this line in a Mac terminal fixed it for me:
/usr/local/opt/python#3.9/bin/python3.9 -m pip install --upgrade pip
I had the same issue. I also first tried the pip3 install pygame which was previously mentioned, before running this line. You may have to do that first. For the individual who said to try
pip install typing
that line of code will simply produce the same error. To fix it, you have to use to the aforementioned command(s).
I also ran into the same problem, because I made the foolish mistake of upgrading pip as suggested by Python.
I fixed this by downloading get_pip.py for python3.4 at https://bootstrap.pypa.io/pip/3.4/get-pip.py and running it:
python get_pip.py
It will automatically download the latest compatible version of pip (19.1.1 in this case).
Try to:
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python get-pip.py
Do the following:
sudo apt update
sudo apt-get upgrade
If there is a problem, do:
sudo apt --fix-broken install
sudo apt-get upgrade
If there is still a problem, remove and recreate your venv. And Reinstall your requirements:
rm -rf venv
python3.9 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
I encountered the same error on Ubuntu 20.04 when using python3.9, I tried to run sudo apt update && sudo apt upgrade.
The output advised me to run sudo apt --fix-broken install, which had solved my problem and python3.9 is running fine now.
I have also met this problem. Any command that starts with pip have the same error, ImportError: No module named 'typing'.
Finally, python -m pip install typing solved it.
I had this error using pip because my Ubuntu installation with Python 2.7 and Python 3.5 were crossed using the versions and pip.
My solution was to uninstall Python 2.7 and pip 2.7. I also uninstalled Python 3.5 and pip 3.
I then installed Python 3.7 using these directions: Installing the latest Python 3.7 on Ubuntu 16.04 and 18.04
I'm not sure if uninstalling 3.5 and adding 3.7 is necessary. You may just be able to remove 2.7 and be good, but this is what worked for me.
Try this one:
pip3 install pygame
It looks like you are importing from the package 'typing' but you do not have it installed. Try installing the package:
pip install typing
I use windows 7 32 bit and python 3.7.
I was trying to install a module with pip and this error came up:
C:\Windows\System32>pip install pyttsx3
Traceback (most recent call last):
File "d:\python\python 3.7\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\python\python 3.7\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\Python\Python 3.7\Scripts\pip.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'
Does anybody know how to fix this?
Make sure you have python path added to the PATH variable. Then run
python -m ensurepip
Could you try?
pip3 install pyttsx3
To me for Ubuntu 20.04 helped the following:
ls -al /usr/bin/python # check before removal that 'python' is link
sudo rm /usr/bin/python # remove link to old version of python
sudo ln -s /usr/bin/python3.8 /usr/bin/python # create new link to actual python version
sudo apt install python3-pip # install missing pip
"Python: No module named pip" was because of missing python3-pip.
Start Python Setup again (Download from here) and be sure to tick that Add python to PATH at the bottom of installation.
Download get-pip.py to a folder on your computer.
Open a command prompt and navigate to the folder containing the
get-pip.py installer.
Run the following command:
python get-pip.py
4-) Verify Installation and Check the Pip Version:
pip -V
This command finally worked for me
python -m pip install --upgrade pip --trusted-host pypi.org --trusted-host files.pythonhosted.org
I am trying to install pip on my Windows 10 system. I got the get-pip.py file and ran the command
python get-pip.py
Here's a snapshot of the terminal
$ python get-pip.py
Collecting pip
Using cached
https://files.pythonhosted.org/packages/46/dc/7fd5df840e
fb3e56c8b4f768793a237ec4ee59891959d6a215d63f727023/pip-19.0.1-py2
.py3-none-any.whl
Collecting setuptools
Using cached
https://files.pythonhosted.org/packages/ff/47/1dfa4795e
24fd6f93d5d58602dd716c3f101cfd5a77cd9acbe519b44a0a9/wheel-0.32.3-py2.py3-
none-any.whl
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-19.0.1 setuptools-40.8.0 wheel-0.32.3
Now when I try to check the version with
pip -V
I get this -
Traceback (most recent call last):
File "runpy.py", line 193, in _run_module_as_main
File "runpy.py", line 85, in _run_code
File "C:\Program Files\Python\python-3.6.3-embed-
amd64\Scripts\pip.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'
Why is this happening? It JUST said pip installed successfully and when I try to see the version to check if its installed, it says No module named 'pip'
Also, I have included C:/Program/Files/Python/python3/Scripts in the PATH variable.
Please help ! ! ! !
After running python get-pip.py, python install-dir will increase dir Lib\site-packages
Method 1. try to cp the pip dir into the python install-dir
or
Method 2. change file python3x._pth in python install-dir,append this line Lib\site-packages
run pip, problem will be solved
Open python37._pth file which is in the root folder of python.
Add Lib\site-packages line.
All will work fine.
The following steps may be followed to install pip on windows:
Download python file: get-pip.py (nearly 1.8 MB size) from link: https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py and save it to your desktop
Go to command prompt and Check your python version: c:> python
From command prompt run: c:> python get-pip.py
The above will install new version of pip. check by running C:> pip --version
You may also update setup tools - C:> pip install --upgrade pip setuptools
I suggest referring to the pip homepage: https://pip.pypa.io/en/stable/installation/
It describes all methods on how to install pip.
I am a win10 user so the solution was to run this command:
py -m ensurepip --upgrade
Use following commands can be used to find out whether pip extraction path is included or not.
>>> import sys
>>> sys.path
if Lib\site-packages path is not included then update file python37._pth.
Run the command again and path should be visible.
pip install <module name> worked successfully for me after this.
Thanks #demianzhang for the hint or even for the solution.
I found files in my Windows lib\site-packages directory
~ip
~ip-20-0.2.dist-info
Renamed them to
pip
pip-20-0.2.dist-info
And it worked to run pip install --upgrade pip
If your Python environment does not have pip installed, there are 2
mechanisms to install pip supported directly by pip’s maintainers:
ensurepip
get-pip.py
Method 1
ensurepip
Python comes with an ensurepip module1, which can install
pip in a Python environment.
Linux: python -m ensurepip --upgrade
MacOc: python -m ensurepip --upgrade
Windows: py -m ensurepip --upgrade
Method 2
get-pip.py This is a Python script that uses some bootstrapping logic
to install pip.
Download the script, from https://bootstrap.pypa.io/get-pip.py.
Open a terminal/command prompt, cd to the folder containing the
get-pip.py file and run:
Linux: python get-pip.py
MacOc: python get-pip.py
Windows: py get-pip.py
Above installation commands are in official python link.
Optional
After successful installation of pip you might want to upgrade pip to latest version
for Linux and MacOs python -m pip install --upgrade pip
for Windows : py -m pip install --upgrade pip
py -m ensurepip --upgrade
this is work for me official docs link you can try multiple methods based on os.
https://pip.pypa.io/en/stable/installation/
I solved my problem by opening my shell as admin
This question already has answers here:
pip: no module named _internal
(30 answers)
Closed last month.
Today, I installed Pipenv via
pip install pipenv
As mentioned in the documentation I went to a test directory and created a new virtual environment using
pipenv shell
and tried to install a package via
pipenv install numpy
I got the following error message:
Installing numpy…
⠧
Error: An error occurred while installing numpy!
Traceback (most recent call last):
File "/Users/florian/.local/share/virtualenvs/test-bJfQ6Jzk/bin/pip", line 7, in <module>
from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'
This error occurs even after reinstalling pipenv, deleting all files and recreate the environment. It also had no impact if I ran pipenv install numpy inside or outside the environment.
Python 3.6.3
Pipenv 11.10.1
Thank you in advance.
I have had the same issue (python 3.5/Ubuntu 16.04LTS). Reinstalling pip with:
sudo apt install python-pip python-pip3 --reinstall
didn't solve the issue with me.
What worked in my case was reinstalling pipenv itself, from pip:
sudo pip3 install pipenv --force-reinstall
If you are running python 2.x or if your system is different than mine, you can try to replace pip3 with pip in the command:
sudo pip install pipenv --force-reinstall
Ubuntu 18.04, Python 3.6 :
Reinstalling pipenv did not work for me. Reinstall pip3 was the only issue, but
sudo apt install python3-pip
did not work too. Found a link to get pip3 in AskUbuntu.com which worked fine :
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py --force-reinstall
After trying around for a while, I fully reinstalled pip. This solved the problem and everything is working now as expected.
Before providing the two commands, which solved the problem, I want to specify some things:
I'm on MacOS
python stands for python3 (added an alias for that, because I only use python3)
pip is on version 9 and NOT 10
Here are both commands:
sudo pip uninstall pip
sudo python get-pip.py
I resolved problem using this command:
pip3 install pipenv --upgrade
The environment pipenv is trying to use may be corrupt for the current project.
Removing it, and re-running pipenv install worked in my case. I am on Fedora 35, where the python virtualenvs are located in ~/.local/share/virtualenvs/, this may be different in your case.
find out which virtualenvs are on your disk:
ls ~/.local/share/virtualenvs/
remove the ones belonging to your project:
rm -rf ~/.local/share/virtualenvs/yourprojectname*
Whenever i try to use pip I get an error. For exampple:
$ sudo pip install gevent-websocket
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2675, in <module>
parse_requirements(__requires__), Environment()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 552, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==0.8.1
I feel tempted to change the value of into pip==0.8.2.. but I dont feel dealing with the consequences of 'hacking' up my installation...
I'm running python 2.7 and pip is at version 0.8.2.
I find this problem in my MacBook, the reason is because as #Stephan said, I use easy_install to install pip, and the mixture of both py package manage tools led to the pkg_resources.DistributionNotFound problem.
The resolve is:
easy_install --upgrade pip
Remember: just use one of the above tools to manage your Py packages.
I replaced 0.8.1 in 0.8.2 in /usr/local/bin/pip and everything worked again.
__requires__ = 'pip==0.8.2'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('pip==0.8.2', 'console_scripts', 'pip')()
)
I installed pip through easy_install which probably caused me this headache.
I think this is how you should do it nowadays..
$ sudo apt-get install python-pip python-dev build-essential
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv
I had this issue when I was using homebrew. Here is the solution from Issue #26900
python -m pip install --upgrade --force pip
Try re-installing with the get-pip script:
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
This is sourced from the pip Github page, and worked for me.
If you're on CentOS make sure you have the YUM package "python-setuptools" installed
yum install python-setuptools
Fixed it for me.
The root of the problem are often outdated scripts in the bin (Linux) or Scripts (Windows) subdirectory. I'll explain this using problem I encountered myself as an example.
I had virtualenv version 1.10 installed in my user site-packages (the fact it's in user site-packages not sytem site-packages is irrelevant here)
pdobrogost#host:~$ which virtualenv
/home/users/pdobrogost/.local/bin/virtualenv
pdobrogost#host:~$ virtualenv --version
1.10
After I upgraded it to version 1.11 I got the following error:
pdobrogost#host:~$ virtualenv --version
Traceback (most recent call last):
File "/home/users/pdobrogost/.local/bin/virtualenv", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2701, in <module>
return self.__dep_map
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 572, in resolve
if insert:
pkg_resources.DistributionNotFound: virtualenv==1.10
File /home/users/pdobrogost/.local/bin/virtualenv mentioned in the error message looked like this:
#!/opt/python/2.7.5/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'virtualenv==1.10','console_scripts','virtualenv'
__requires__ = 'virtualenv==1.10'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('virtualenv==1.10', 'console_scripts', 'virtualenv')()
)
There, we see that virtualenv script was not updated and still requires previously installed version 1.10 of virtualenv.
Now, reinstalling virtualenv like this
pdobrogost#host:~$ pip install --user --upgrade virtualenv
Downloading/unpacking virtualenv from https://pypi.python.org/packages/py27/v/virtualenv/virtualenv-1.11.1-py27-none-any.whl#md5=265770b61de41d34d2e9fdfddcdf034c
Using download cache from /home/users/pdobrogost/.pip_download_cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fpy27%2Fv%2Fvirtualenv%2Fvirtualenv-1.11.1-py27-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...
does not help (neither pip install --user --upgrade --force-reinstall virtualenv) because script /home/users/pdobrogost/.local/bin/virtualenv is left unchanged.
The only way I could fix this was by manually removing virtualenv* scripts from /home/users/pdobrogost/.local/bin/ folder and installing virtualenv again. After this, newly generated scripts refer to the proper version of the package:
pdobrogost#host:~$ virtualenv --version
1.11
I was able to resolve this like so:
$ brew update
$ brew doctor
$ brew uninstall python
$ brew install python --build-from-source # took ~5 mins
$ python --version # => Python 2.7.9
$ pip install --upgrade pip
I'm running w/ the following stuff (as of Jan 2, 2015):
OS X Yosemite
Version 10.10.1
$ brew -v
Homebrew 0.9.5
$ python --version
Python 2.7.9
$ ipython --version
2.2.0
$ pip --version
pip 6.0.3 from /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.3-py2.7.egg (python 2.7)
$ which pip
/usr/local/bin/pip
I was facing the similar problem in OSx. My stacktrace was saying
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: setuptools>=11.3
Then I did the following
sudo pip install --upgrade setuptools
This solved the problem for me. Hope someone will find this useful.
On Mac OS X (MBP), the following (taken from another answer found herein) resolved my issues:
C02L257NDV33:~ jjohnson$ brew install pip
Error: No available formula for pip
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can:
sudo easy_install pip
C02L257NDV33:~ jjohnson$ sudo easy_install pip
Clearly the root cause here is having a secondary method by which to install python (in my case Homebrew). Hopefully, the people responsible for the pip script can remedy this issue since its still relevant 2 years after first being reported on Stack Overflow.
I had this problem because I installed python/pip with a weird ~/.pydistutils.cfg that I didn't remember writing. Deleted it, reinstalled (with pybrew), and everything was fine.
In my case (sam problem, but other packages) there was no version dependency. A sequence of pip uninstall and pip insstall did help.