Error After Upgrading Pip: Cannot Import Name 'Main'

Error after upgrading pip: cannot import name 'main'

You must have inadvertently upgraded your system pip (probably through something like sudo pip install pip --upgrade)

pip 10.x adjusts where its internals are situated. The pip3 command you're seeing is one provided by your package maintainer (presumably debian based here?) and is not a file managed by pip.

You can read more about this on pip's issue tracker

You'll probably want to not upgrade your system pip and instead use a virtualenv.

To recover the pip3 binary you'll need to sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall.

If you want to continue in "unsupported territory" (upgrading a system package outside of the system package manager), you can probably get away with python3 -m pip ... instead of pip3.

Pip error (cannot import name 'main' from 'pip') after upgrading to python 3.8 (Debian 9)

I ran into a similar issue, when I was trying to copy a self compiled python build in a docker container to prod machine. I am going to make a guess for the first issue and provide solution for the second:

Issue 1:

ImportError: cannot import name 'main' from 'pip' (/usr/local/lib/python3.8/site-packages/pip/__init__.py)

Here anaconda installed python3 is taking preference over OS level Python3. Since your python3 was not in /usr/bin but pip3 was, I am assuming at sometime, python3 was removed from /usr/bin. Deducted from update here

Issue 2:

bash: /usr/bin/pip3: /usr/bin/python3: bad interpreter: No such file or directory

Basically what is happening here is shebang is pip3 script is pointing to /usr/bin/python3 but on your machine python was NOT available there, so it is failing. Since you made python with altinstall, even pip was renamed to pip3.8 and using that would have worked fine. Alternately, updating the pip3 script with correct python location might have also helped, but on my compiled python the import is as follows: from pip._internal.cli.main import main

How to fix pip : cannot import name main? (pip is installed and pip3 works fine)

The problem turns out to be the same as bug in pip 10.0 although I'm using pip 18.0, the bug is still there.

The solution is by modifying file: /usr/bin/pip sudo vim /usr/bin/pip

from:

from pip import main
if __name__ == '__main__':
sys.exit(main())

to

from pip import __main__
if __name__ == '__main__':
sys.exit(__main__._main())

credits : ImportError: cannot import name main when running pip --version command in windows7 32 bit

Python3.6 ImportError: cannot import name 'main' after upgrading pip from 8.1.1 to 19.0.1

This is a common issue as referenced here : https://github.com/pypa/pip/issues/5221

You are trying to use the pip, which is shipped with the Debian system. You better try to avoid using that pip at any cost.

Please use python3 -m pip install package instead of the system pip which you have in the debian system.

I also recommend using venv - virtual environments for keeping your system environment safe.

ImportError: cannot import name main when running pip --version command in windows7 32 bit

Even though the original question seems to be from 2015, this 'bug' seems to affect users installing pip-10.0.0 as well.

The workaround is not to modify pip, however to change the way pip is called. Instead of calling /usr/bin/pip call pip via Python itself. For example, instead of the below:

pip install <package>

If from Python version 2 (or default Python binary is called python) do :

python -m pip install <package>

or if from Python version 3:

python3 -m pip install <package> 

Python PIP is throwing error - ImportError: cannot import name main

You can try to uninstall pip and pip env.

Then reinstall pip and then try to again install pipenv. If this time
it does not work then you need to use pip and virtualenv instead of
pip env.

Uninstall both of them and this time install pip and virtualenv

You can configure pycharm to work with virtualenv.

Anyway these commands worked for me

For uninstalling

python3 -m pip3 uninstall pip3

sudo -H pip3 install --upgrade pip
sudo -H pip3 install pipenv

Now try executing 'pipenv'

If it still does not work try upgrading your python3.

If you are still using python2.7 then replace pip3 with pip



Related Topics



Leave a reply



Submit