MWorks python matplotlib circular import

I am trying to run an MWorks task that involves running python code under the hood. Here is the code:

This code worked a couple years ago, but now when I follow the README instructions there I get the and run main.mwel I get the following error:

00:00:06:  Received new codec, updating variable registry.
00:00:06:  Received new codec, updating variable registry.
00:00:06:  WARNING: Eye window can't find the following variables: , , , , , , 
00:00:06:  WARNING: Variable for success trials: success was not found.
00:00:06:  WARNING: Variable for failure trials: failure was not found.
00:00:06:  WARNING: Variable for ignored trials: ignore was not found.
00:00:08:  ERROR: Python execution failed: Traceback (most recent call last):
  File "/var/folders/_h/nj1cpgkx7yl40q0b31fq3swr0000gn/T/MWorks/Experiment Cache/_Users_nicholaswatters_Desktop_20220801_testing_main.mwel/tmp/task.py", line 52, in <module>
    from matplotlib import pyplot as plt
  File "/opt/miniconda3/envs/mworks/lib/python3.8/site-packages/matplotlib/__init__.py", line 129, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "/opt/miniconda3/envs/mworks/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 35, in <module>
    from matplotlib import _api, _c_internal_utils
ImportError: cannot import name '_c_internal_utils' from partially initialized module 'matplotlib' (most likely due to a circular import) (/opt/miniconda3/envs/mworks/lib/python3.8/site-packages/matplotlib/__init__.py)

00:00:08:  ERROR: Failed to create object. 
Extended information:
	reason: Python file execution failed
	location: line 33, column 1
	object_type: resource/python_file
	ref_id: idp105553141429631
	parser_context: mw_create

00:00:08:  ERROR: Failed to parse experiment /var/folders/_h/nj1cpgkx7yl40q0b31fq3swr0000gn/T/MWorks/Experiment Cache/_Users_nicholaswatters_Desktop_20220801_testing_main.mwel/tmp/_Users_nicholaswatters_Desktop_20220801_testing_main.mwel.xml

I’m using a conda version 25.7.0 virtual environment, and run_demo.py works, so the python environment is okay on its own. I’m using mworks version 0.13.

How can I get the mwel script running?

Thank you,

Nick

Hi Nick,

MWorks 0.13 embeds Python 3.11. From the error messages, it looks like conda is using Python 3.8. I suspect the import is failing on a compiled module, as those are usually built for a specific Python version.

If you update your conda environment to use Python 3.11, I think the import error will disappear. If not, please let me know!

Cheers,
Chris

Thank you Chris, that fixed it — it’s working now!