# Transferring Python files to server machine

**URL:** <https://mworks.discourse.group/t/transferring-python-files-to-server-machine/261>\
**Category:** Support\
**Created:** [April 23, 2019, 1:16pm UTC](https://mworks.discourse.group/t/transferring-python-files-to-server-machine/261 "2019-04-23T13:16:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [April 23, 2019, 1:16pm UTC](https://mworks.discourse.group/t/transferring-python-files-to-server-machine/261/1 "2019-04-23T13:16:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [April 23, 2019, 2:44pm UTC](https://mworks.discourse.group/t/transferring-python-files-to-server-machine/261/2 "2019-04-23T14:44:57Z")

</div>

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](https://mworks.github.io/documentation/latest/components/file_resource.html). 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:

3. In your “main” Python script, before attempting to import additional Python code, ensure that `sys.path` includes the directory:

I’ve attached an example experiment and associated Python files that demonstrate this approach.

One important point: As [noted in the docs](https://mworks.github.io/documentation/latest/components/resources.html), 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

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [April 23, 2019, 2:44pm UTC](https://mworks.discourse.group/t/transferring-python-files-to-server-machine/261/3 "2019-04-23T14:44:57Z")

</div>

Attachment: [python\_files.zip](https://mworks.discourse.group/uploads/short-url/vHbSxrPNfszqlYZfSbo1nz1vLI6.zip) (1.06 KB)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 8:53pm UTC](https://mworks.discourse.group/t/transferring-python-files-to-server-machine/261/4 "2022-07-19T20:53:50Z")

</div>


