cli icon indicating copy to clipboard operation
cli copied to clipboard

Issue with debian based system after upgrading python to 3.10

Open hemulin opened this issue 3 years ago • 1 comments

Setup

  • Running Lubuntu 20.04
  • httpie from apt (v1.0.3-2)
  • Recently upgraded Python to 3.10

Issue

When running in terminal, invocation leads to exception and termination:

Traceback (most recent call last):
  File "/usr/bin/http", line 11, in <module>
    load_entry_point('httpie==1.0.3', 'console_scripts', 'http')()
  File "/usr/lib/python3/dist-packages/httpie/__main__.py", line 10, in main
    from .core import main
  File "/usr/lib/python3/dist-packages/httpie/core.py", line 23, in <module>
    from httpie.client import get_response
  File "/usr/lib/python3/dist-packages/httpie/client.py", line 11, in <module>
    from httpie.input import SSL_VERSION_ARG_MAPPING
  File "/usr/lib/python3/dist-packages/httpie/input.py", line 12, in <module>
    from collections import namedtuple, Iterable, OrderedDict
ImportError: cannot import name 'Iterable' from 'collections' (/usr/lib/python3.10/collections/__init__.py)

Cause

The Iterable object changed location in 3.10 from the root of the module into collections.abc

Confirming

Changing line 12 in input.py (in /usr/lib/python3/dist-packages/httpie/input.py) that imports the Iterable confirms that. Importing from collections.abc solved the issue.

Possible solution

I wanted to make a PR that quickly patches that minor issue, in the form of:

try:
    # Python <= 3.9
    from collections import Iterable
except ImportError:
    # Python > 3.9
    from collections.abc import Iterable

(a more rigorous solution would check the actual version of python but nvm :shrug:)

However, I couldn't locate in the repo source code the input.py file to edit.

Maybe someone else would find this useful.

hemulin avatar Mar 23 '22 00:03 hemulin

Hey @hemulin, the code you mention is not present on the recent releases. Unfortunately our debian package is stuck at a very old version, which we currently are trying to upgrade. In the meanwhile, would you mind giving a shot at installing from Snap or Pip?

isidentical avatar Mar 23 '22 08:03 isidentical

Hi @isidentical and apologies for the (super) late reply.

Installation via pip worked for me.

For anyone coming here, make sure that you install it using the right python version. In my case, and because of my configuration, running python3 -m pip install httpie gave first the line

Defaulting to user installation because normal site-packages is not writeable

and the python default version was 2.7, which later on resulted with ImportError: No module named pkg_resources

After uninstalling this, I install with sudo which went to the right place and worked eventually as expected.

hemulin avatar Mar 06 '23 16:03 hemulin