Hi Chris,
I noticed that if an MWorks protocol uses a python file to run simple functions, any other files that this python file requires must be stored on the MwServer machine, rather than on the MwClient machine. The same is not true for sounds/images/python-code/etc., so I just wanted to make sure you are aware of this (or I am not missing something?).
It’s easy enough to work around for our in-lab setups, but seems less than ideal for in-cage or remote rigs.
Cheers,
Rishi
Hi Rishi,
Yes, MWorks has no way of knowing what other Python files your Python code requires, so it can’t copy them over automatically. However, you can explicitly tell MWorks to copy them over by including them as a file resource. In short:
-
Put all the Python files you need in a directory (e.g. python
).
-
Include that directory as a resource in your experiment:
resource ('python')
-
In your “main” Python script, before attempting to import additional Python code, ensure that sys.path
includes the directory:
import sys
if 'python' not in sys.path:
sys.path.insert(0, 'python')
I’ve attached an example experiment and associated Python files that demonstrate this approach.
One important point: As noted in the docs, if your experiment declares any resources, then all other required files (e.g. images, sounds) must also be declared as resources. The simplest approach is probably to dump everything in a single directory (e.g. resources
) and then use relative paths in to that directory (e.g. resources/images/img1.png
).
Chris
Attachment: python_files.zip (1.06 KB)