christiansandberg / canopen

CANopen for Python
http://canopen.readthedocs.io/
MIT License
437 stars 195 forks source link

canopen not works with python 3.12 #470

Closed prunith closed 2 months ago

prunith commented 3 months ago

With python 3.12 i got error: File "C:\Users\100034799\AppData\Local\Programs\Python\Python312\Lib\site-packages\canopen\objectdictionary__init.py", line 281, in class ODVariable: File "C:\Users\100034799\AppData\Local\Programs\Python\Python312\Lib\site-packages\canopen\objectdictionary\init__.py", line 290, in ODVariable INTEGER24: IntegerN(24), TypeError: Struct() argument 1 must be a str or bytes object, not int

acolomb commented 3 months ago

That is strange indeed. We did see this error on the builder for the documentation, but I could not reproduce locally. A fix is already committed on the master branch, you might want to try installing that.

If you can confirm this is fixed on master, we will make a new point release soon.

sveinse commented 3 months ago

This is a strange error. I just retested with a fresh python 3.12.2 in virtual environment with the current master and I am not able to reproduce the error. Which version of canopen do you use?

acolomb commented 3 months ago

Well, current master does include a fix. @prunith most likely tested with the latest PyPI release? That does not have the fix.

prunith commented 3 months ago

@acolomb you are right i use latest release 2.3.0 installed with pip and not the master.

sveinse commented 3 months ago

I tried running a fresh 24.04 ubuntu docker container and installed system python3 (3.12.3) and made a venv and installed canopen from pypi in it. Still no failure.

There is something in your setup which I'm curious what triggers this.

acolomb commented 3 months ago

Me too, curious. Because it didn't happen with the released version on my Ubuntu 24.04 with Python 3.12 either. But the same code failed on the readthedocs deployment (in context of Sphinx autodoc importing the modules). The fix is basically not relying on asterisk imports from the datatypes module, but pulling in the classes via name.

prunith commented 3 months ago

In my case i instelled IDLE python 12 for windows and installed package with pip command

sveinse commented 3 months ago

From the path in the first post it seems you are installing canopen globally into the system and not via a virtual environment? @prunith

prunith commented 3 months ago

Yes but same issue occures with pycharm and venv based on installed python 12

ayavilevich commented 3 months ago

fyi, I had this issue with Python 3.12 but when I upgraded to 3.12.4 it went away.

erlend-aasland commented 2 months ago

ISTM this can be closed as not-a-bug.