Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip3 list comes AssertionError

when I do pip3 list in the terminal, it comes the following error:

cliu@cliu-ubuntu:~$ pip3 list
Exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/commands/list.py", line 80, in run
    self.run_listing(options)
  File "/usr/lib/python3/dist-packages/pip/commands/list.py", line 142, in run_listing
    self.output_package_listing(installed_packages)
  File "/usr/lib/python3/dist-packages/pip/commands/list.py", line 151, in output_package_listing
    if dist_is_editable(dist):
  File "/usr/lib/python3/dist-packages/pip/util.py", line 367, in dist_is_editable
    req = FrozenRequirement.from_dist(dist, [])
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 299, in from_dist
    assert len(specs) == 1 and specs[0][0] == '=='
AssertionError

Storing debug log for failure in /home/cliu/.pip/pip.log 

Anyone knows how to fix this?

like image 449
fluency03 Avatar asked May 29 '15 22:05

fluency03


People also ask

What does AssertionError mean?

The meaning of an AssertionError is that something happened that the developer thought was impossible to happen. So if an AssertionError is ever thrown, it is a clear sign of a programming error.

What is AssertionError in Python?

In Python, assert is a simple statement with the following syntax: assert expression[, assertion_message] Here, expression can be any valid Python expression or object, which is then tested for truthiness. If expression is false, then the statement throws an AssertionError .

What causes assertion Error Python?

The assert Statement When it encounters an assert statement, Python evaluates the accompanying expression, which is hopefully true. If the expression is false, Python raises an AssertionError exception.


2 Answers

Judging by the bug linked in the comments, this can be fixed by upgrading to the latest Pip. Since doing that within Ubuntu/Debian's packaging system is moderately nontrivial, I think it would probably be simpler to just install a new version of Pip into a Virtualenv. Once you've created the virtualenv, you can upgrade to the latest Pip with this command:

pip install --upgrade pip
like image 99
Kevin Avatar answered Oct 20 '22 14:10

Kevin


Though there is an accepted answer here, that did not work for me. So, my answer might help others who face the same issue. This bug was fixed with a single line commit here.

https://github.com/pypa/pip/commit/6cab71f422f2425b4d2283023c9e955f9663dde6

The solution is to change the line from

assert len(specs) == 1 and specs[0][0] == '=='

to

assert len(specs) == 1 and specs[0][0] in ["==", "==="]

The line number varies from version to version but, the debug message should make it easier to find. In your case it is line 299, in the file "/usr/lib/python3/dist-packages/pip/__init__.py"

like image 37
Ravi Teja Avatar answered Oct 20 '22 14:10

Ravi Teja