Running python files on iOS

Aida Piccato's Avatar

Aida Piccato

21 Jan, 2020 06:06 PM

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

  1. Support Staff 1 Posted by Christopher Sta... on 21 Jan, 2020 06:09 PM

    Christopher Stawarz's Avatar

    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).

    Cheers,
    Chris

  2. 2 Posted by Aida Piccato on 21 Jan, 2020 07:42 PM

    Aida Piccato's Avatar

    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

  3. Support Staff 3 Posted by Christopher Sta... on 22 Jan, 2020 04:29 PM

    Christopher Stawarz's Avatar

    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. However, as noted in the docs, 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

  4. Christopher Stawarz closed this discussion on 24 Jan, 2020 05:28 PM.

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

Keyboard shortcuts

Generic

? 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