Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'InvalidSchemeCombination' from 'pip._internal.exceptions'

I am quite new to programming so don't be mad if I get something wrong. I updated pip to its latest version (something like 21.x.x) and I tried to install the Detectron2 Git repo. But anything related with pip (even when checking its version) I get the following Traceback:

Traceback (most recent call last):
  File "/Users/user/opt/anaconda3/bin/pip", line 7, in <module>
    from pip._internal.cli.main import main
  File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 8, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/cmdoptions.py", line 22, in <module>
    from pip._internal.cli.progress_bars import BAR_TYPES
  File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/progress_bars.py", line 9, in <module>
    from pip._internal.utils.logging import get_indentation
  File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pip/_internal/utils/logging.py", line 14, in <module>
    from pip._internal.utils.misc import ensure_dir
  File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pip/_internal/utils/misc.py", line 29, in <module>
    from pip._internal.locations import get_major_minor_version, site_packages, user_site
  File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pip/_internal/locations/__init__.py", line 9, in <module>
    from . import _distutils, _sysconfig
  File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pip/_internal/locations/_sysconfig.py", line 8, in <module>
    from pip._internal.exceptions import InvalidSchemeCombination, UserInstallationInvalid
ImportError: cannot import name 'InvalidSchemeCombination' from 'pip._internal.exceptions' (/Users/user/opt/anaconda3/lib/python3.8/site-packages/pip/_internal/exceptions.py)

Is there a solution for my problem? I also tried downgrading to an earlier version but as I said any comment with pip inside gives me this Traceback...

If anyone out there can help me I would be so grateful!

like image 354
SchmidtiT Avatar asked May 08 '21 09:05

SchmidtiT


People also ask

How to resolve the import error cannot import name in Python?

To resolve the ImportError: Cannot import name, modify the x.py file. Instead of importing the y module at the start of the x.py file, write at the end of the file. Now rerun, and you can see the following output.

Is it bad practice to use Pacman and Pip together?

I know, unfortunately too only now, that it is not a good practice to use both pacman and pip, and most of all use pip with sudo. Now I having problems using pip, as it says that it doesn't have permission to edit files. I guess this is due to the fact that files in the packages of interest are located in

Is there any reason to run Pip in elevated mode?

There should never, ever be any reason you need to run pip in elevated mode. Had same problem on macOS as well, it's a common issue across platforms. Show activity on this post.

How do you import a module in Python?

Python implements at least three different ways to import modules. You can use the import statement, the from statement, or the built-in __import__ function. Modules are performed during import, and new functions and classes won’t see in the module’s namespace until the def (or class) statement has been executed.


1 Answers

I was having the same error after upgrading to pip 20.x.x, there is a solution on GitHub(https://github.com/pypa/pip/issues/5599) which helped me to understand the problem, but it doesn't help me. So let's come to the solution

Solution

  1. Manually remove or delete the pip file and pip-20.2.4-py3.7.egg-info file from the directory, which in your case is located in /Users/user/opt/anaconda3/lib/python3.7/site-packages and for some it's in /home/user/anaconda3/lib/python3.7/site-packages.

  2. Now use conda remove --force pip to completely remove pip from your system.

  3. Finally, use conda install -c anaconda pip to install pip in your anaconda environment.

For me, it worked, hope it will work for you too

best of luck

like image 52
kriptonian Avatar answered Oct 19 '22 11:10

kriptonian