# New MWorks Python

**URL:** <https://mworks.discourse.group/t/new-mworks-python/272>\
**Category:** Support\
**Created:** [March 20, 2019, 1:31pm UTC](https://mworks.discourse.group/t/new-mworks-python/272 "2019-03-20T13:31:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [March 20, 2019, 1:31pm UTC](https://mworks.discourse.group/t/new-mworks-python/272/1 "2019-03-20T13:31:02Z")

</div>

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.  
[https://mworks.tenderapp.com/discussions/suggestions/450-python-3-support](https://mworks.tenderapp.com/discussions/suggestions/450-python-3-support)  
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 “python37.zip/ctypes/ **init**.py”, line 7, in   
ModuleNotFoundError: No module named ‘\_ctypes’

I found this issue:  
[https://bugs.python.org/issue26598](https://bugs.python.org/issue26598)

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

Thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [March 20, 2019, 2:00pm UTC](https://mworks.discourse.group/t/new-mworks-python/272/2 "2019-03-20T14:00:52Z")

</div>

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__']
RTLD_GLOBAL = 0

sys.path.append('/Users/cstawarz/Library/Python/3.7/lib/python/site-packages')
import zmq

```

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [March 20, 2019, 2:22pm UTC](https://mworks.discourse.group/t/new-mworks-python/272/3 "2019-03-20T14:22:39Z")

</div>

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/_ctypes.cpython-37m-darwin.so

```

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

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [March 20, 2019, 2:35pm UTC](https://mworks.discourse.group/t/new-mworks-python/272/4 "2019-03-20T14:35:23Z")

</div>

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.cpython-37m-darwin.so'
_ctypes_spec = importlib.util.spec_from_file_location('_ctypes', _ctypes_path)
importlib.util.module_from_spec(_ctypes_spec)

import sys

sys.path.append('/Users/cstawarz/Library/Python/3.7/lib/python/site-packages')
import zmq

```

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [March 20, 2019, 4:34pm UTC](https://mworks.discourse.group/t/new-mworks-python/272/5 "2019-03-20T16:34:38Z")

</div>

Great.  
How did you install Python 3.7 to  
/Library/Frameworks/Python.framework/Versions/3.7/  
?  
Homebrew?

thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [March 20, 2019, 5:18pm UTC](https://mworks.discourse.group/t/new-mworks-python/272/6 "2019-03-20T17:18:06Z")

</div>

I used the installer from [python.org](https://www.python.org). 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.

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 8:54pm UTC](https://mworks.discourse.group/t/new-mworks-python/272/7 "2022-07-19T20:54:54Z")

</div>


