ModuleNotFoundError: No module named 'pip._internal.cli' - python

Need some help here.
I have two versions of pip and pip3 installed in different location.
When I try to do a pip install package-name it throws Error as:
ModuleNotFoundError: No module named 'pip._internal.cli'
pip 18.1 from /project/miniconda/lib/python3.7/site-packages/pip (python 3.7)
$ which pip
/project/miniconda/bin/pip
$ which pip3
/usr/local/bin/pip3
$ pip -V
pip 18.1 from /project/miniconda/lib/python3.7/site-packages/pip (python 3.7)
$ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal.cli'```
Since I don't have super user access, I cannot modify pip._internal.cli.main to pip.internal.cli.main.
Please help.

Please upgrade pip with python -m pip install --upgrade --force-reinstall pip.
You can try to install any package with: python -m pip install package-name for python2.7 and python3 -m pip install package-name for python3.
Using python -m pip install instead of just pip install is recommended. The reason is that it will use the correct interpreter for your python installation, specially if you have many versions installed. More details here: https://snarky.ca/why-you-should-use-python-m-pip/

Try this it worked for me
python3 -m pip install --user --upgrade pip
Image Link for code

Related

Pip does not install in USER_SITE

my specific problem is with pip 9.0.3 (no other version tested) on linux.
When I try to install a package for locally for my linux user using
$ pip3 install --user numpy
...
Successfully installed numpy-1.18.1
I get
$ python3 -m numpy
/usr/bin/python3: No module named numpy
As far as I know, pip3 should install in
$ python3 -m site
...
USER_BASE: '/home/username/.local' (exists)
USER_SITE: '/home/username/.local/lib/python3.6/site-packages' (exists)
ENABLE_USER_SITE: True
but the directory is empty.
But what I've found are modules in /home/username/.username/modules which seems to be installed by pip3.
How can I configure pip to use the correct USER_SITE?
Q: Which pip/python is used?
$ which pip3
/usr/bin/pip3
$ pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
$ python3 --version
Python 3.6.8
Q: how does sys.path looks like?
$ python3
>>> import sys
>>> sys.path
['', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/home/username/.local/lib/python3.6/site-packages', '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages']
Q: Have you tried to upgrade your pip first?
I have no super-user privileges on this machine (why I try to install in USER_SITE).
Q: Do you have local configuration files like here?
The online doc describes pip 20.0.2 instead of 9.0.3 or similar.
However, there are no such config files like
/home/username/.config/pip/pip.conf
/home/username/.pip/pip.conf
/etc/pip.conf
/etc/xdg/pip/pip.conf
Q: have you tried to install/upgrade in USER_SITE?
Yes. But without the correct path, it will not work.
$ python3 -m pip install -U --user pip
...
Successfully installed pip-20.0.2
$ which pip
~/.username/scripts/pip
$ pip --version
Traceback (most recent call last):
File "/home/username/.username/scripts/pip", line 7, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal'

Pipenv "ModuleNotFoundError: No module named 'pip'" after upgrading to python3.7

I am using ubuntu 18. The default python3 version is 3.6. I updated to 3.7 today and update the alternatives to point to python3.7.
I can use python3.7 by typing python3. I can also use pip3 --version (20.0.2).
I can activate the virtual environment by using pipenv shell. But I cannot install package using pipenv install . It gives me the following error:
pipenv.exceptions.InstallError]: ['Traceback (most recent call last):', ' File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip", line 5, in <module>', ' from p
ip._internal.cli.main import main', "ModuleNotFoundError: No module named 'pip'"]
ERROR: ERROR: Package installation failed...
Running which pip3: /usr/local/bin/pip3
Running which pipenv: /usr/local/bin/pipenv
Type pip3 inside pipenv gives:
Traceback (most recent call last):
File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip3", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
python2 -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade pip
After upgrading pip (or pip3, in this case) if the following occurs:
$ ~ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'
Force a reinstall of pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Verify install:
$ ~ pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
Now pip3 install <package> and pip3 install --user <package> (for user-level installs) will work correctly.
There should never, ever be any reason you need to run pip in elevated mode.
(note: For Python 2.7, just replace python for python3, and pip for pip3)
Had the same issue on macOS as well, it's a common issue across platforms.
I found the answer here:
Setting up a virtualenv: No module named 'pip'
Seems like it is a bug.
I install pipenv using --re flag which is equivalent to virtualenv venv --no-setuptools.
Then I run python get-pip.py inside pipenv.
It works. I can install package now.
But I don't know the reason why...

Unable to properly install pip3 for python3

I am having trouble properly installing pip3 for python3. It appears that I have installed pip and pip3 successfully.
whereis pip
pip: /usr/local/bin/pip /usr/local/bin/pip3.7
whereis pip3
pip3: /usr/bin/pip3 /usr/local/bin/pip3 /usr/local/bin/pip3.7 /usr/share/man/man1/pip3.1.gz
What makes me curious is when I type:
pip --version
pip 19.0.3 from /home/fmd/.local/lib/python3.6/site-packages/pip (python 3.6)
This gives proper result but when I do the same for pip3 I this:
pip3 --version
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
I have referred
https://pip.pypa.io/en/stable/installing/
How do you uninstall the package manager "pip", if installed from source?. And tried to uninstalling and reinstalling pip3 but it dosent seem to work I get the same error as above. How do I remove this error?
My system is:
> NAME="Ubuntu" VERSION="18.04.2 LTS (Bionic Beaver)" ID=ubuntu
> ID_LIKE=debian PRETTY_NAME="Ubuntu 18.04.2 LTS" VERSION_ID="18.04"
My bad seems like I installed pip3.7 binary
pip3.7 --version
pip 19.0.3 from /home/fmd/.local/lib/python3.6/site-packages/pip (python 3.6)
I would install python3 dependencies using pip3.7 rather than pip3
for example pip3.7 install numpy and so on.

Cannot import a package installed with pip

I'm trying to add a package for my python(2.7.6) on linux ,
I used the command:
pip install crc16
and It sends back :
Requirement already satisfied (use --upgrade to upgrade): crc16 in /usr/local/lib/python3.5/site-packages
As should be.
But when i try to run a python script it says
Traceback (most recent call last):
File "mos.py", line 1, in <module>
import crc16
ImportError: No module named crc16
My guess is that pip and the python aren't on the same version.
EDIT**
answer: i used easy_install-2.7 crc16
and then python2.7 mos.py
You could have done
python -m pip install <module>
Your pip is catching the 3.5 version. You must specifically install pip for 2.7 version for your code to work. This is how it's done:
$ sudo apt-get install python2-pip
$ sudo pip2 install crc16

pip broke. how to fix DistributionNotFound error?

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.

Categories

Resources