ImportError: no module named 'operator'



  • Trying to use python's "operator" module in version 3.7.2 on the pycom and I'm getting below:

    Initializing filesystem as FatFS!
    Traceback (most recent call last):
      File "main.py", line 10, in <module>
    ImportError: no module named 'operator'
    Pycom MicroPython 1.20.0.rc0 [v1.9.4-9f0896a] on 2018-12-08; GPy with ESP32
    Type "help()" for more information.
    

    I've tried manually putting in the operator module but I get the following error:

    Initializing filesystem as FatFS!
    Traceback (most recent call last):
      File "main.py", line 10, in <module>
      File "/flash/lib/operator.py", line 110
    SyntaxError: invalid syntax
    Pycom MicroPython 1.20.0.rc0 [v1.9.4-9f0896a] on 2018-12-08; GPy with ESP32
    Type "help()" for more information.
    

    The offending line in the operator.py is:

    def matmul(a, b):
        "Same as a @ b."
        return a @ b
    

    Is there a firmware update or something I need to do to get it working for python version 3.5 and higher?



  • @randomrnti That works :) glad you got it sorted.



  • @paul-thornton No worries, I ended up copying across the mainline's operator.py and removing the lines of code implementing the matmul. Luckily for me I didn't need to use the matrix multiplication.



  • Hey,

    as you've discovered the micropython implementation is seperate to that of "mainline" python and thus lags behind in features and support.

    @ support is currently missing. Your going to need to implement your own Matrix multiply function without using the @ Operator.


Log in to reply
 

Pycom on Twitter