# Running python files on iOS

**URL:** <https://mworks.discourse.group/t/running-python-files-on-ios/207>\
**Category:** Support\
**Created:** [January 21, 2020, 6:06pm UTC](https://mworks.discourse.group/t/running-python-files-on-ios/207 "2020-01-21T18:06:22Z")\
**Posts on this page:** 5\
**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:** [January 21, 2020, 6:06pm UTC](https://mworks.discourse.group/t/running-python-files-on-ios/207/1 "2020-01-21T18:06:22Z")

</div>

Hi Chris,

I’m in the process of making a version of my experiment to use on iOS. My current protocol runs a python file to set experiment and trial-level variables. Running this protocol now gives me the following error:

ERROR: Failed to create object.  
Extended information:  
reason: No factory for object type: action/run\_python\_file

Is running python files possible on iOS? The version of MWorks on the iPad I’m using is 0.8.1

Best,

Aída

---

<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:** [January 21, 2020, 6:09pm UTC](https://mworks.discourse.group/t/running-python-files-on-ios/207/2 "2020-01-21T18:09:19Z")

</div>

Hi Aída,

> Is running python files possible on iOS? The version of MWorks on the iPad I’m using is 0.8.1

Yes, it is possible, but you need MWorks 0.9 (the version currently [on the App Store](https://apps.apple.com/us/app/mworks/id1389408331?ls=1)).

Cheers,  
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:** [January 21, 2020, 7:42pm UTC](https://mworks.discourse.group/t/running-python-files-on-ios/207/3 "2020-01-21T19:42:40Z")

</div>

Hi Chris,

Thanks for the quick reply! I’ve run into another issue: the Python file is  
now run by the server (the client is running on my Mac), but I’m having an  
issue reading in a pickle file used in the python script to set block-level  
variables, as I’m getting the following error:

No such file or directory: '~/Documents/MWorks/Data/subject\_0.pkl’

I’ve saved the .pkl file in what I think is the above directory, but I’m  
not super familiar with file paths in iOS - is there a particular place I  
be saving the .pkl file on the iPad so that the Python file can access it?

I’m also happy to come into your office whenever is convenient for you if  
the question is unclear!

Thanks again,

Aída

---

<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:** [January 22, 2020, 4:29pm UTC](https://mworks.discourse.group/t/running-python-files-on-ios/207/4 "2020-01-22T16:29:07Z")

</div>

Hi Aída,

The best and sanest way to get the pickle file to the server is to add it to the experiment as a [file resource](https://mworks.github.io/documentation/latest/components/file_resource.html). However, as [noted in the docs](https://mworks.github.io/documentation/latest/components/resources.html), once your experiment contains a file resource, _all_ supporting files (images, Python scripts, etc.) must be declared as resources.

To make this simpler, you could move all the supporting files and directories (e.g. `constants.py`, `images`) into a single subdirectory called `resources` and then include that one directory as a resource:

```
resource ('resources')

```

Once that’s done, you’ll need to change the supplied paths for all supporting files to be relative to the resources directory. For example, instead of

```
run_python_file ('utils.py')

```

you would use

```
run_python_file ('resources/utils.py')

```

Alternatively, you could leave the files and directories where they are and declare separate resources for each.

If you want help setting this up, feel free to stop by my office.

Cheers,  
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:** [July 19, 2022, 8:37pm UTC](https://mworks.discourse.group/t/running-python-files-on-ios/207/5 "2022-07-19T20:37:06Z")

</div>


