question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Circular imports in pip._vendor.requests

See original GitHub issue

Looks like since pip 18.1 there’s a circular import problem. All versions including 18.1 and 19.1.1 produce something like this (traceback from 19.1.1 release):

Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in <module>
    from pip._internal import main
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/__init__.py", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/cli/main_parser.py", line 12, in <module>
    from pip._internal.commands import (
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/commands/__init__.py", line 6, in <module>
    from pip._internal.commands.completion import CompletionCommand
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/commands/completion.py", line 6, in <module>
    from pip._internal.cli.base_command import Command
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/cli/base_command.py", line 25, in <module>
    from pip._internal.index import PackageFinder
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/index.py", line 39, in <module>
    from pip._internal.utils.packaging import check_requires_python
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/utils/packaging.py", line 10, in <module>
    from pip._internal import exceptions
ImportError: cannot import name exceptions

Contents of the bin script:

$ cat `which pip`                                                                                                                                  #!/usr/bin/python2.7

# -*- coding: utf-8 -*-
import re
import sys

from pip._internal import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

Note that 18.0 doesn’t have the problem.

This happens on Ubuntu 18.04 if it matters (yes, pip is installed globally, python-pip deb package not installed of course).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ionelmccommented, Jul 23, 2019

There’s still some crappy code if importing something from vendor first makes everything fall apart imo. Sure, from an user’s perspective it doesn’t matter (no one should be doing that) but from an maintainer’s perspective you gonna get bitten by that sooner or later.

0reactions
chrahuntcommented, Dec 28, 2019

I think we can leave this open until such a test is implemented or someone has a good argument against it.

I had put this previously in #6498 (comment), and after trying to implement it my argument against this test would be that we would have to either:

  1. exclude vendored dependencies, which wouldn’t’ve helped this situation, or
  2. maintain a platform-specific blacklist of modules for our vendored dependencies, which would be a decent amount of effort for very little benefit
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do circular imports seemingly work further up in the ...
I think the answer by jpmc26, while by no means wrong, comes down too heavily on circular imports. They can work just fine,...
Read more >
Python Circular Imports
Circular importing is a form of circular dependency that is created with the import statement in Python. For example, let's analyze the ...
Read more >
Vendoring Policy - pip documentation v22.3.1
Vendored libraries MUST not be modified except as required to successfully vendor them. · Vendored libraries MUST be released copies of libraries available...
Read more >
Python pip breaks and how to recover?
Reproduce $ pip install git+https://github.com/BingLingGroup/autosub.git@origin $ pip uninstall autosub (to remove dependecies of autosub, ...
Read more >
Solving Circular Import Problem - Python
Circular importing is a conceptual error that is formed due to circular dependency created with the import statement in our Python program. Python...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found