| Reference | Downloads | Github

How to build .exe executible on Windows?

Hi all:

It’s well known that Python is interpretative, so basically we need a Python interpreter to run Python scripts, as well as other libraries or packages. Psychopy should be installed in addition if we are to run Psychopy experiments. So it is generally impossible to run any Psychopy experiments if one has only a .psyexp file or a scrip at hand. But I want to make it possible. One way I can figure out is to somehow generate an all-in-one .exe executible (assume we are talking about Windows), which can run alone without any special requirements on the environments by including all dependent libraries and packages on, e.g., a machine just having Windows installed. Can anyone please tell me how to do this? Thanks a lot!

PS, in case someone ask about my motivation, I just want to administrate experiment in a distributive way, so participants are not required to come to my lab to conduct the experiment. Anyone on this planet who has a Windows computer can download the .exe file and do the experiment, so I can have more participants and therefore more data.

Compiling python programs to an executable is absolutely doable, but in my experience it can be a major frustrating headache, and I find the documentation for when things go wrong to be severely lacking.

I’ve had pretty good success with it with windows using cx_freeze. It’s a bit much to explain here, I’ll leave it to you and Google, but if I remember correctly you write a setup script and run it. Here’s a simple one for something I made a while ago:

#!/usr/bin/env python

from cx_Freeze import setup, Executable

#run this with python build

# Extra, non-python files. Maybe like a conditions file?
includefiles = ['my.db']
includes = []


    name = "My Experiment",
    version = "1",
    options = {'build_exe': {'include_files':includefiles}},
    description = "By Me", executables = [Executable("")]

This would (hopefully) make a folder with an executable in it. To distribute it you could zip it up. If you wanted it to install like a usual Windows program with an installer, that’s also doable, but is something I didn’t get around to learning. I think it’s a subsequent step.

Beware that when you compile, if the user has a different CPU architecture than the one used when compiling (i.e. 64-bit, 32-bit, ARM) it won’t work. Well, I take that back, generally 32-bit (including your python version!) will run on 64-bit but not the other way around. I personally found that compiling something on Windows 7 typically worked for Win 8 and Win 10, but the reverse wasn’t always true.

Lastly, depending on the type of your experiment, sometimes knowing the hardware intimately is important for getting usable results that could be compared across machines.

There’s a lot more that could be said about this topic, maybe others will have something different to say. But in short, I would say it’s absolutely possible, but in my experience it’s a pain and if you’re unlucky and things don’t “just work” there’s a steep learning curve. Maybe (probably) someone knows a better way.

Daniel is quite right. The psychopy docs also discuss doing it in py2exe (similar to cx_freeze):

And this has been discussed before several times before e.g.:!searchin/psychopy-users/py2exe|sort:relevance

But briefly: It’s possible, it’s generally painful, it isn’t supported by us. In the future there will be an option to run your studies from a browser but compiling your experiment into a single exe file isn’t something I plan to spend time on supporting.

Is the option to run studies from a browser available yet from psychopy?