Optommp error :No module named 'O22SIOUT'

Hi,

I am running the following python3 code and get this error. Running it on the epic in local (localhost).
Traceback (most recent call last):
File “optoMMP.py”, line 1, in
import optommp
File “/usr/lib/python3.4/site-packages/optommp/init.py”, line 1, in
import O22SIOUT
ImportError: No module named ‘O22SIOUT’

Code:
import optommp
import sys
grvEpic = optommp.O22MMP()
groov = optommp.O22MMP()
groov.SetDigitalPointState(int(sys.argv[1]),int (sys.argv[2]))
groov.close()

Can you help on solving it?

rgds

Hugues

Hi Hugues, welcome to the forums!

It looks like you’re one of the first people to use this module with python3 rather than Python 2.7. It was not originally written for python3, but I have found a workaround to get it running.

What it boils down to is that python3 handles relative imports differently than 2.7 so we’ll need to change line 1 of init.py to explicitly say where to find O22SIOUT.

Here’s my workaround:

  1. Download a copy of the same optommp repository that pip uses:
    wget https://github.com/optodeveloper/optommp/archive/refs/heads/master.zip

  2. Unzip the master file:
    unzip master.zip

  3. Delete the zip file (optional, but you won’t need it again):
    rm master.zip

  4. Navigate into the unzipped folder (this is also where I create and run my python3 script):
    cd optommp-master

  5. Open the init file with your text editor of choice:
    nano optommp/__init__.py
    or
    vim optommp/__init__.py

  6. Modify ONLY line 1, replacing “import O22SIOUT” with:
    from optommp import O22SIOUT

  7. Save the file. Now, in the optommp-master/ folder, you can create and run your python3 scripts using this modified module. There may be ways to get around the pathing, but the main thing is that the script should be in the same folder as the optommp subfolder.
    Then what should happen is that when you run the script here, instead of using the module you installed with pip at usr/lib/python3.4/site-packages/, python3 should use this modified version from wherever you unzipped the repo (in my case that’s just /home/opto/optommp-master/).


Please let me know if that does or doesn’t get you up and running, and again, welcome to the forums!

1 Like

Terry,

Thank you for the quick support.
I ll check it up tomorrow when I get back to the office. Meanwhile I have submitted a pull request on Github for it.

Hi @torchard
I was able to set this up for python 3 and everything works except

GetScratchPadStringArea

function… Upon somechecking i was able to fix it by changing the line

        rawSize = self.UnpackReadResponse(sizeData, 'c')[1:-1]

to

        rawSize = self.UnpackReadResponse(sizeData, 'c')[2:-1]

looks like some internal way of handling bytes has changed from python2 to python3… Can you please review it once and confirm…

I appreciate you pointing this out! I can confirm that this works fine with Python 2.7 but errors out with Python 3.

I’m considering what is going to be the best way to fix this without any regression for older Python versions, especially since 2.7 is already installed on groov systems by default…

I’ll update this thread when I find a more permanent solution, but as you found, the quick fix is to change that line to ignore the initial character with [2:-1] in the local package file.

1 Like

Hi @torchard

When reading a string of length 8 characters, the previous fix was also ineffective. Currently, my application requires reading a maximum of 60 characters. To address this, I have hardcoded the length and cleaned up the string after reading. However, a more effective solution would be greatly appreciated.