Using Pyserial with MWorks Python

Hi Chris,

As we mentioned in our meeting last week, Margaret is working on trying to incorporate an Arduino device for use with MWorks. Our primary issue at the moment is that we’ve not been able to use the pyserial plugin for Python, despite downloading Python 3.7, and I’ve been a bit confused as to how we can install new 3rd-party plugins to work with MWorks’ embedded version of Python. I’ve installed pyserial with Anaconda, but MWorks continues to report that it can’t find the serial module - do you have any suggestions?

Thank you for your help!

Best,

Jack

Hi Jack,

The current nightly build embeds Python 3.9, not 3.7. If you install pyserial using a Python 3.9 version of Anaconda, then all that’s left to do is tell MWorks’ bundled Python where to find it. You do this by adding the installation directory to sys.path. At the beginning of your Python script, include something like this:

import sys 
anaconda_path = '/Users/jack/anaconda/envs/py39/lib/python3.9/site-packages'
if anaconda_path not in sys.path:
    sys.path.insert(0, anaconda_path)

import serial

Note that I haven’t used Anaconda in many years, and your site-packages path may look different. But that’s the only part that should need to change.

Cheers,
Chris