New MWorks Python

mhisted's Avatar


20 Mar, 2019 01:31 PM

Hi Chris,

I'm testing the new embedded Python 3.7 in the latest MWorks nightly.
Our embedded Python code uses zmq to talk to hardware.

Following your instructions, I've installed zmq to a user directory.
Python does find the zmq module.

But when I try to import zmq, I'm getting this error:
, line 9, in _load_libzmq
    import sys, ctypes, platform, os
  File "", line 7, in <module>
ModuleNotFoundError: No module named '_ctypes'

I found this issue:

Could that be the problem? Or do you have any other ideas why this might not work?


  1. Support Staff 1 Posted by Christopher Sta... on 20 Mar, 2019 02:00 PM

    Christopher Stawarz's Avatar

    Hi Mark,

    The problem is that MWorks' bundled Python doesn't include ctypes. (ctypes doesn't support ARM/iOS at all, and it was causing some problems on macOS, so I opted to omit it.)

    Fortunately, the zmq package doesn't actually need it (except on Windows, I think). I was able to import it via MWorks like this:

    import sys
    sys.modules['ctypes'] = sys.modules['__main__']
    import zmq


  2. Support Staff 2 Posted by Christopher Sta... on 20 Mar, 2019 02:22 PM

    Christopher Stawarz's Avatar

    A less hacky and more general solution (which would allow you to actually use ctypes if you needed it) would be to create a symbolic link to the .so file in a non-MWorks Python installation. For example:

    $ cd $HOME/Library/Python/3.7/lib/python/site-packages
    $ ln -s /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/

    Then, in your Python file, you could just import zmq as usual, without messing with sys.modules.


  3. Support Staff 3 Posted by Christopher Sta... on 20 Mar, 2019 02:35 PM

    Christopher Stawarz's Avatar

    One more option, which also gives you a usable ctypes but doesn't require that you create a symbolic link:

    import importlib.util
    _ctypes_path = '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/'
    _ctypes_spec = importlib.util.spec_from_file_location('_ctypes', _ctypes_path)
    import sys
    import zmq


  4. 4 Posted by mhisted on 20 Mar, 2019 04:34 PM

    mhisted's Avatar

    How did you install Python 3.7 to


  5. Support Staff 5 Posted by Christopher Sta... on 20 Mar, 2019 05:18 PM

    Christopher Stawarz's Avatar

    I used the installer from However, you can install Python any way you want, as long as it matches the version bundled with MWorks (currently 3.7). Just be sure to use the correct path to the _ctypes module in your Python script.


  6. Christopher Stawarz closed this discussion on 25 Mar, 2019 04:15 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac