Libcomedi python3 binding on Ubuntu 24.04 / Debian 12

14 views
Skip to first unread message

Han Hartgers

unread,
May 7, 2025, 4:53:23 AMMay 7
to Comedi: Linux Control and Measurement Device Interface
Dear all,

Can it be that the python bindings for libcomedi are not working for python3.x?

I tried the example on my ubuntu 24.04 (and Debian 12) and I get the following error:
hansan@Desk-computer:~$ python
Python 3.12.3 (main, Feb  4 2025, 14:48:35) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import comedi
>>> device = comedi.comedi_open("/dev/comedi0")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'comedi' has no attribute 'comedi_open'
>>> 

This does work on older Ubuntu versions like 18.04.  Is there a way to fix this?

I also tried pycomedi (https://pypi.org/project/pycomedi/)  but that has trouble to get compiled.

My problem looks to be similar as of Bernd Porr in 2018

There it was suggested that libcomedi 0.11.x would/could solve this. But that does not look to be the case:

hansan@Desk-computer:~$ sudo apt list --installed | grep -i comedi
libcomedi-dev/noble,now 0.11.0+5-1.1build1 amd64 [installed]
libcomedi0t64/noble,now 0.11.0+5-1.1build1 amd64 [installed]
python3-comedilib/noble,now 0.11.0+5-1.1build1 amd64 [installed]
hansan@Desk-computer:~$ uname -a
Linux Desk-computer 6.8.0-59-lowlatency #61.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Apr 18 11:13:23 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

 Is there a way to fix this all to use Python3 to interface with comedi based measurement cards ?

Kind regards,

Han

Ian Abbott

unread,
May 7, 2025, 9:22:07 AMMay 7
to comed...@googlegroups.com, Han Hartgers
Hi,

On 06/05/2025 15:29, Han Hartgers wrote:
> Dear all,
>
> Can it be that the python bindings for libcomedi are not working for
> python3.x?
>
> I tried the example on my ubuntu 24.04 (and Debian 12) and I get the
> following error:
> hansan@Desk-computer:~$ python
> Python 3.12.3 (main, Feb  4 2025, 14:48:35) [GCC 13.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import comedi
>>>> device = comedi.comedi_open("/dev/comedi0")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: module 'comedi' has no attribute 'comedi_open'
>>>>
>
> This does work on older Ubuntu versions like 18.04.  Is there a way to
> fix this?

According to a comment by Éric Piel on launchpad bug #1797258:

https://bugs.launchpad.net/ubuntu/+source/comedilib/+bug/1797258

... the problem seems to be that the module is installed in the wrong
place, so comedi.comedi needs to be imported, e.g.:

import comedi.comedi as c
device = c.comedi_open("/dev/comedi0")

That workaround is not great for portability though, as we expect to be
able to use 'import comedi'.

> I also tried pycomedi (https://pypi.org/project/pycomedi/)  but that has
> trouble to get compiled.
>
> My problem looks to be similar as of Bernd Porr in 2018
> See https://groups.google.com/g/comedi_list/c/MjI7FGp_Xyw/m/J5n2dlIoBAAJ
>
> There it was suggested that libcomedi 0.11.x would/could solve this. But
> that does not look to be the case:
>
> hansan@Desk-computer:~$ sudo apt list --installed | grep -i comedi
> libcomedi-dev/noble,now 0.11.0+5-1.1build1 amd64 [installed]
> libcomedi0t64/noble,now 0.11.0+5-1.1build1 amd64 [installed]
> python3-comedilib/noble,now 0.11.0+5-1.1build1 amd64 [installed]
> hansan@Desk-computer:~$ uname -a
> Linux Desk-computer 6.8.0-59-lowlatency #61.1-Ubuntu SMP PREEMPT_DYNAMIC
> Fri Apr 18 11:13:23 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

There was at least one build bug in comedilib 0.11.0, which presumably
was fixed by one of the package maintainer's patches.

comedilib-0.12.0 was released about 5 years ago, but doesn't seem to
have been picked up by either Debian or Ubuntu yet.

I really ought to finalize a new release 0.13.0 because it is way overdue!

>
>  Is there a way to fix this all to use Python3 to interface with comedi
> based measurement cards ?
>
> Kind regards,
>
> Han

Another option is to build and install comedilib from source, but it
will install to /usr/local by default, and you may have to set the
PYTHONPATH environment variable before importing the comedi module.

--
-=( Ian Abbott <abb...@mev.co.uk> || MEV Ltd. is a company )=-
-=( registered in England & Wales. Regd. number: 02862268. )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-

Han Hartgers

unread,
May 7, 2025, 11:02:05 AMMay 7
to comed...@googlegroups.com
Dear Ian,

On Wed, May 7, 2025 at 9:21 PM Ian Abbott <abb...@mev.co.uk> wrote:
Hi,

On 06/05/2025 15:29, Han Hartgers wrote:
> Dear all,
>
> Can it be that the python bindings for libcomedi are not working for
> python3.x?
>

> This does work on older Ubuntu versions like 18.04.  Is there a way to
> fix this?

According to a comment by Éric Piel on launchpad bug #1797258:

https://bugs.launchpad.net/ubuntu/+source/comedilib/+bug/1797258

... the problem seems to be that the module is installed in the wrong
place, so comedi.comedi needs to be imported, e.g.:

import comedi.comedi as c
device = c.comedi_open("/dev/comedi0")

That workaround is not great for portability though, as we expect to be
able to use 'import comedi'.

Thanks this is indeed working for me as well.
 
> I also tried pycomedi (https://pypi.org/project/pycomedi/)  but that has
> trouble to get compiled.
>
I need to correct myself here;  Compiling/installing pycomedi looks to be working for both Ubuntu 25.04 and Debian 12.  I must have done something wrong when I tried earlier.
 
>
>   Is there a way to fix this all to use Python3 to interface with comedi
> based measurement cards ?
>
> Kind regards,
>
> Han

Another option is to build and install comedilib from source, but it
will install to /usr/local by default, and you may have to set the
PYTHONPATH environment variable before importing the comedi module.


I will look at this as well.  I should get that working.   you pointed me in the right direction.
 

Ian Abbott

unread,
May 21, 2025, 5:07:59 AMMay 21
to comed...@googlegroups.com
I found a better workaround is to add a new file:

/usr/lib/python3/dist-packages/comedi/__init__.py

containing the single line:

from .comedi import *
Reply all
Reply to author
Forward
0 new messages