how to make pip works again? - python

I tried to make pip3 as the main pip in my Linux by writing this code
alias pip=pip3
and after that what ever command I give to pip, it keeps on giving the same error message:
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'

For linux, you can use the argument -m of python bin.
python3 -m pip
so, you can use this allias
alias pip="python3 -m pip"

Use python3 -m pip install --user packagename

Related

No Module named pip when running it

When I use pip3 I get this error:
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/usr/bin/pip3", line 7, in <module>
from pip import main
ModuleNotFoundError: No module named 'pip'
I tried to reinstall PIP but still reported this error, but I use python3 -m ensurepip
It told me to install Xcode command line
$ python3 -m ensurepip
$ xcode-select: Failed to locate 'python3.9', requesting installation of command line developer tools.
I had this problem when I was trying to update the pip and it failed.
This always works for me:
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:
python get-pip.py
font: https://pip.pypa.io/en/stable/installation/
Try to install python3.9 as suggested by the terminal.

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...

pip install not working. How to resolve pip precedence issues?

[qq88#qq88-pc ~]$ which -a pip
/home/qq88/.local/bin/pip
/usr/bin/pip
So it seems that after the python 3.8 update there is a conflict between which install takes precedence - right now it is /home/qq88/.local/bin/pip and not /usr/bin/pip. This causes issues when doing pip install like:
[qq88#qq88-pc ~]$ pip install ipython
Traceback (most recent call last):
File "/home/qq88/.local/bin/pip", line 10, in <module>
sys.exit(main())
TypeError: 'module' object is not callable
I went and installed it with python -m pip install ipython but:
[qq88#qq88-pc ~]$ ipython
Traceback (most recent call last):
File "/home/qq88/.local/bin/ipython", line 6, in <module>
from IPython import start_ipython
ModuleNotFoundError: No module named 'IPython'
How do I run this now?
And more importantly, how do I make /usr/bin/pip take precedence or whatever else would resolve this?
I think you can do it using the alias in your shell:
$ alias pip='/usr/bin/pip'
Then if you execute $ alias pip you should get :
alias pip='/usr/bin/pip'

python3.4 pip ImportError: No Module named 'pkg_resources'

pip is not working in my python3.4
$ pip install django
Traceback (most recent call last):
File "usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'
$ pip
Traceback (most recent call last):
File "usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'
How do I fix this? What's the problem? Thanks
i just ran into the same error, here is what i've done to fix it:
sudo apt-get remove --purge python-pkg-resources
sudo apt-get install ubuntu-desktop
Try >sudo pip install django< I think that ought to do it
well then I suspect your pip is messed up so try
sudo apt-get install --reinstall python-pkg-resources
however if you are using Python 3 you may need to adjust to insure that you get the Python 3 environment set up rather than the P2 default
see here for more on that
How to use pip with Python 3.x alongside Python 2.x

How to install a package with pip locally?

Hello I've installed a local version of pip using
python get-pip.py --user
After that I can't find the path of pip, so I run:
python -m pip install --user Cython
Finally I can't import Cython
import Cython
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'Cython'
Use virtualenv, it is used to create isolated python environments (check this quick guide http://docs.python-guide.org/en/latest/dev/virtualenvs/ )
python -m pip install --user Cython
should probabably be
pip install --user cython

Categories

Resources