Using Python

Hi Chris,
After I switched to version 0.9, I was not able to run script properly in the bundled python. Python stoped immediately without giving error. I suspect that the supporting libraries were not available to Mworks or there was version mismatch. Are there any ways to opt out and use non-mworks Python? I am much comfortable working and debugging in my old Anaconda environment. Thank you very much!

Hi Jing,

In MWorks 0.9, the embedded Python version (i.e. the Python that executes the run_python_file and run_python_string actions) changed from 2.7 to 3.7. If your Python script is no longer working in MWorks 0.9, then you’re probably hitting one or more of the following issues:

  1. Your script uses syntax that’s no longer valid in Python 3.
  2. Your script uses a standard-library module that’s no longer available in Python 3.
  3. Your script depends on compiled, third-party extensions (e.g. installed via Anaconda) that are built against Python 2.7.

Issue 3 is the easiest to check and remedy. Just make sure that you’re using the Python 3.7 version of Anaconda.

If the problem is with your script itself, then the 2to3 tool should help with any necessary updates.

Cheers,
Chris

Hello Chris,
Thank you for the prompt reply. I will adapt to python 3.7 one way or another.
This maybe a separate but related question. The reason I updated from 0.8 to 0.9 and later ones is because I have updated macOS to Mojave that causes MWServer 0.8 stucks at loading, same encounter as described in previous inquiryhttps://mworks.tenderapp.com/discussions/problems/388-mwserver-hang . Is there a fix to the deadlock issue in version 0.8 with new mac OS. Sorry if this is an unreasonable request.

Thanks again!

  • Jing

Is there a fix to the deadlock issue in version 0.8 with new mac OS.

No. If you need that fix, you have to use MWorks 0.9.

Chris

Hi Chris,
MWorks uses mac’s built-in python. right? could you please inform how to make site-packages installed under conda accessible to python script called in mserver conduit? Thank you!

Hi Jing,

could you please inform how to make site-packages installed under conda accessible to python script called in mserver conduit?

Do you mean a Python script called via run_python_file? If so, then you need to add the following to your script, before it attempts to import any Anaconda packages:

import sys
sys.path.append('/Users/jing/anaconda3/lib/python3.7/site-packages')

The actual path string may be different, depending on where and how you’ve installed Anaconda.

If you’re actually running your script via a server-side conduit, then MWorks has no control over how it’s executed. You launch the script yourself, using the Python interpreter of your choice, and MWorks interacts with it via inter-process communication.

MWorks uses mac’s built-in python. right?

In MWorks 0.8, the Python actions used macOS’ built-in Python. However, they don’t in MWorks 0.9. Instead, MWorks embeds its own copy of Python. (The macOS Python is still at version 2.7.)

Cheers,
Chris

Hi Chris, I misunderstood. It must be the later case. I am running a script via Python script bridge.
The confusion part is that error msg reported in the bridge console is not present in the anaconda environment. It makes hard to find out what’s going on. My application is that python does heavy computing on its own and periodically sends update to mworks’ variables. what is your recommendation?
Thank you again!

Could I stop by your office to see what’s happening?

Chris

Hi Chris,

The python seems working now after unistalling and installing opencv, and i have also changed path in the bash_profile. Although i am not completely sure which one helped.
I left MIT and found MWorks still is essential part of research, thanks to your service. I really appreciate it, and will contact you via if more problems.

  • Jing