pipenv update --outdated | TypeError: '>' not supported between instances of '_Version' and 'str'

Created on 26 May 2019  路  3Comments  路  Source: pypa/pipenv

Issue description

Describe the issue briefly here.
pipenv update --outdated


    return callback(*args, **kwargs)
  File "/home/jimmy/.pyenv/versions/3.7-dev-debug/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/jimmy/.pyenv/versions/3.7-dev-debug/lib/python3.7/site-packages/pipenv/cli/command.py", line 484, in update
    do_outdated(pypi_mirror=state.pypi_mirror)
  File "/home/jimmy/.pyenv/versions/3.7-dev-debug/lib/python3.7/site-packages/pipenv/core.py", line 1653, in do_outdated
    for pkg in project.environment.get_outdated_packages()
  File "/home/jimmy/.pyenv/versions/3.7-dev-debug/lib/python3.7/site-packages/pipenv/environment.py", line 350, in get_outdated_packages
    pkg for pkg in self.get_package_info(pre=pre)
  File "/home/jimmy/.pyenv/versions/3.7-dev-debug/lib/python3.7/site-packages/pipenv/environment.py", line 351, in <listcomp>
    if pkg.latest_version._version > pkg.parsed_version._version
TypeError: '>' not supported between instances of '_Version' and 'str'

I am using a package with special version mark 3.3.0.dev.3a8168,

I think 3.3.0.dev.3a8168 causes this problem.

Dependency Resolution Type Vendored Dependencies

All 3 comments

try to test pipenv update --outdated with the latest commit of git master branch.

Traceback (most recent call last):
  File "/home/jimmy/.pyenv/versions/3.7-dev-debug/bin/pipenv", line 11, in <module>
    load_entry_point('pipenv', 'console_scripts', 'pipenv')()
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/cli/command.py", line 483, in update
    do_outdated(pypi_mirror=state.pypi_mirror)
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/core.py", line 1808, in do_outdated
    for pkg in project.environment.get_outdated_packages()
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/environment.py", line 435, in get_outdated_packages
    pkg for pkg in self.get_package_info(pre=pre)
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/environment.py", line 435, in <listcomp>
    pkg for pkg in self.get_package_info(pre=pre)
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/environment.py", line 407, in get_package_info
    with self.get_finder() as finder:
  File "/home/jimmy/.pyenv/versions/3.7-dev-debug/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/mnt/fedora-home/jimmy/workspace/devel/github/pypa/pipenv/pipenv/environment.py", line 394, in get_finder
    process_dependency_links=pip_options.process_dependency_links,
AttributeError: 'Values' object has no attribute 'process_dependency_links'
  • pipenv update is OK
  • only this happens to pipenv update --outdated

Hi,

I've observed a similar error message using Shapely. The command pipenv run pip search Shapely shows the available version Shapely (1.6.4.post2). If I try to update Shapely calling pipenv update --outdated generates an error.

Steps to reproduce

mkdir test && cd test
pipenv shell
pipenv install Shapely==1.6.4
pipenv update --outdated

Error message:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/bin/pipenv", line 10, in <module>
    sys.exit(cli())
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/cli/command.py", line 484, in update
    do_outdated(pypi_mirror=state.pypi_mirror)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/core.py", line 1653, in do_outdated
    for pkg in project.environment.get_outdated_packages()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/environment.py", line 350, in get_outdated_packages
    pkg for pkg in self.get_package_info(pre=pre)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/environment.py", line 351, in <listcomp>
    if pkg.latest_version._version > pkg.parsed_version._version
TypeError: '>' not supported between instances of 'tuple' and 'NoneType'

Workaround

If you rerun pipenv install Shapely==1.6.4.post2 (including the version suffix post2) the command pipenv update --outdated works as expected.

Debugging the problem

The source of the error lies in pipenv/environment.py:

    def get_outdated_packages(self, pre=False):
        return [
            pkg for pkg in self.get_package_info(pre=pre)
            if pkg.latest_version._version > pkg.parsed_version._version
        ]

At this point, two versions are compared (latest_version vs. parsed_version) and the comparison fails for the Shapely package. Running the snippet

[(pkg.latest_version._version, pkg.parsed_version._version) for pkg in self.get_package_info(pre=pre)]

generates the output

[...,
(_Version(epoch=0, release=(1, 6, 4), dev=None, pre=None, post=('post', 2), local=None),
  _Version(epoch=0, release=(1, 6, 4), dev=None, pre=None, post=None, local=None)),
...]

Looking at the file pipenv/patched/notpip/_vendor/packaging/version.py indicates that _Version is just a collections.namedtuple. In my case, one of the elements inside the namedtuple is None and that causes the comparison error. This is easy to reproduce:

import collections
T = collections.namedtuple('T', ['a', 'b'])
t1 = T(a=0, b=0)
t2 = T(a=1, b=1)
t3 = T(a=None, b=2)

# OK --> True
print(t1 < t2)

# Fails with: TypeError: '>' not supported between instances of 'int' and 'NoneType'
print(t2 > t3)

Maybe someone can help to fix the problem. I'm not sure what would be the best approach, e.g.

  1. Guarantee that no element of the namedtuple is None --> this maybe causes error prone comparison results
  2. Use Version instead of _Version for the comparison. Version seems to be a child class of BaseVersion which implements the comparison operators.
    ...

Best regards,
Andreas

Thanks for the helpful debugging, this seems like a bug in packaging that I can triage upstream if they haven't caught it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

erinxocon picture erinxocon  路  3Comments

FooBarQuaxx picture FooBarQuaxx  路  3Comments

bgjelstrup picture bgjelstrup  路  3Comments

Californian picture Californian  路  3Comments

leileigong picture leileigong  路  3Comments