Python 3.11 and collections
NFSpeedy opened this issue · comments
Hi,
I am using Python 3.11 and when importing obd, I get an exception:
ImportError Traceback (most recent call last)
File ~/.local/share/virtualenvs/pyserial_rasp-JGlkwlhx/lib/python3.11/site-packages/pint/compat/__init__.py:64
63 try:
---> 64 from collections import Chainmap
65 except ImportError:
ImportError: cannot import name 'Chainmap' from 'collections' (/Users/nfspeedy/.pyenv/versions/3.11.0/lib/python3.11/collections/__init__.py)
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
Cell In [11], line 1
----> 1 import obd
3 connection = obd.OBD() # auto-connects to USB or RF port
5 cmd = obd.commands.SPEED # select an OBD command (sensor)
File ~/.local/share/virtualenvs/pyserial_rasp-JGlkwlhx/lib/python3.11/site-packages/obd/__init__.py:41
10 ########################################################################
11 # #
12 # python-OBD: A python OBD-II serial module derived from pyobd #
(...)
37 # #
38 ########################################################################
40 from .__version__ import __version__
...
---> 16 from collections import MutableMapping
17 if sys.version_info < (3, 0):
18 from thread import get_ident
ImportError: cannot import name 'MutableMapping' from 'collections' (/Users/nfspeedy/.pyenv/versions/3.11.0/lib/python3.11/collections/__init__.py)
Is Py3.11 going to be supported?
in files :
/.local/lib/python3.11/site-packages/pint/util.py
and
/.local/lib/python3.11/site-packages/pint/compat/chainmap.py
change :
from collections import Mapping
to
from collections.abc import Mapping
in files :
/.local/lib/python3.11/site-packages/pint/util.py
and
/.local/lib/python3.11/site-packages/pint/compat/chainmap.py
change :
from collections import Mapping
to
from collections.abc import Mapping
Thanks, this works perfectly with python 3.11
Python 3.10 still complaints about something but just upgrade to 3.11 and it will work 😁
Can you send a PR with those changes?
Can you send a PR with those changes?
I would. But that has to be changed in the "Pint" package which is not part of this repo right?
I see there is a "Pint" version 0.20.1 which is newer than the currently used 19 version. Maybe upgrading would solve the issue?
Ah, whoops. I didn't look closely enough.
It seems like this has been fixed in pint
awhile ago. Are you using an old version?
I simply did pip3 install obd
and got that version (19) of pint
.
I would expect this version to be set in obd, isn't it?
I've submitted a PR to update the tests to test Python 3.11, they seem to pass there: #255
I just bumped into this issue today, trying to run via python 3.10. I tried using the branch from #255 instead and it seems to be working!
Are you able to review the PR then? That will allow me to merge it
On python 3.10.9 I receive the same import error due to the deprecation of classes in collections by using the standard pip install obd.
installing the git version results in errors due to the pint package. it requires v 0.20.* but fails to import it correctly:
ImportError: cannot import name 'register_unit_format' from 'pint.formatting'
what version of pint are you using specifically?
Can you include details on what fails with the latest from git? Let's get that fixed then we can focus on a release
Apologies for the delayed response. I was using pint 0.20.1.
I initially worked around this by reinstalling obd through the standard pip install obd. Then i manually edited pint as suggested by @Ch1x3.
I tried to reproduce the error via the github installation again but found that it now works. This is strange as the dependencies/default setup is the same.
For reference the steps I took are:
pip install git+https://github.com/brendan-w/python-OBD
I successfully installed obd-0.7.1 pint-0.20.1 and successfully imported it.
@alistair23 What's the path forward to a new release/how can I help? That'd be sweet.
Apologies for the delayed response. I was using pint 0.20.1.
I initially worked around this by reinstalling obd through the standard pip install obd. Then i manually edited pint as suggested by @Ch1x3.
I tried to reproduce the error via the github installation again but found that it now works. This is strange as the dependencies/default setup is the same.
For reference the steps I took are:
pip install git+https://github.com/brendan-w/python-OBD
I successfully installed obd-0.7.1 pint-0.20.1 and successfully imported it.
I was wondering if it would be possible to have a new release with this patch included? It's been found to be very helpful in fixing the problem in Python 3.11.
I totally agree, especially because PyPi doesn't allow for packages to have git dependencies for security reasons (see here for an example). So a solution really needs to be hacked together for this to be included.
As mentioned before I'm willing to help however possible to get this cut and released. Cheers!
I have asked @brendan-w to push a release
released as 0.7.2