Transferring Python files to server machine

Rishi Rajalingham's Avatar

Rishi Rajalingham

23 Apr, 2019 01:16 PM

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.


  1. Support Staff 1 Posted by Christopher Sta... on 23 Apr, 2019 02:44 PM

    Christopher Stawarz's Avatar

    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:

    1. Put all the Python files you need in a directory (e.g. python).
    2. Include that directory as a resource in your experiment:

      resource ('python')
    3. 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).


  2. Christopher Stawarz closed this discussion on 26 Apr, 2019 01:32 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac