Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.11 and collections #252

Open
NFSpeedy opened this issue Nov 26, 2022 · 18 comments
Open

Python 3.11 and collections #252

NFSpeedy opened this issue Nov 26, 2022 · 18 comments

Comments

@NFSpeedy
Copy link

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?

@r4ut
Copy link

r4ut commented Dec 16, 2022

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

@Mrc527
Copy link

Mrc527 commented Jan 23, 2023

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 😁

@alistair23
Copy link
Collaborator

Can you send a PR with those changes?

@Mrc527
Copy link

Mrc527 commented Jan 24, 2023

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?

@alistair23
Copy link
Collaborator

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?

@Mrc527
Copy link

Mrc527 commented Jan 24, 2023

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?

@alistair23
Copy link
Collaborator

I've submitted a PR to update the tests to test Python 3.11, they seem to pass there: #255

@Stealthmate
Copy link

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!

@alistair23
Copy link
Collaborator

Are you able to review the PR then? That will allow me to merge it

@CaptainKatsuura
Copy link

CaptainKatsuura commented May 30, 2023

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'

@lamemakes
Copy link

what version of pint are you using specifically?

@alistair23
Copy link
Collaborator

Can you include details on what fails with the latest from git? Let's get that fixed then we can focus on a release

@CaptainKatsuura
Copy link

@alistair23 @lamemakes

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.

@lamemakes
Copy link

@alistair23 What's the path forward to a new release/how can I help? That'd be sweet.

@NitsujY
Copy link

NitsujY commented Jul 6, 2023

@alistair23 @lamemakes

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.

@lamemakes
Copy link

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!

@alistair23
Copy link
Collaborator

I have asked @brendan-w to push a release

@brendan-w
Copy link
Owner

released as 0.7.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants