Hello everyone !
I recently started making a PsychoPy experiment, and quickly got on packaging the experiment so that I can distribute it to people conveniently. I can’t use the JS version because I have incompatible components in my experiment, and asking people to download PsychoPy on their computers is just not possible in my case.
Since I have already some experience with pyinstaller, I wanted to try with my experiment. After -much- googling and hair pulling, I managed to do it ! Here are the few caveats I encountered, hoping it can help people in my situation.
Here is the script I use on my Windows machine (the ^
character is used for breaking down the command over several lines) :
"C:\Program Files\PsychoPy\python.exe" -m PyInstaller ^
--onefile ^
--add-binary "freetype.dll;." ^
--add-data "C:\Program Files\PsychoPy\Lib\site-packages\psychopy;psychopy" ^
--add-data "*.csv;." ^
--add-data "AudioSamples;AudioSamples" ^
.\sound_test.py
Let’s break it down for clarity :
"C:\Program Files\PsychoPy\python.exe" -m PyInstaller ^
It is mandatory to use the same Python version as PsychoPy to launch pyinstaller, otherwise it doesn’t work. Also, case matters for PyInstaller
!
--onefile ^
This option makes pyinstaller generate a single executable file
--add-binary "freetype.dll;." ^
This line is the result of much hair pulling. The freetype
module needs to load an external DLL that is not included automatically by pyinstaller. WARNING: it must be 64 bit ! At least in my case I guess, because I have a 64-bit machine and I’m trying to generate a 64-bit executable. You can compile the DLL from source, or use a pre-compiled binary. Then, place it in the same folder as the experiment Python file.
--add-data "C:\Program Files\PsychoPy\Lib\site-packages\psychopy;psychopy" ^
This line was required for me because I use the standalone PsychoPy package. If you installed PsychoPy through pip, you may be able to delete it as it’s possible pyinstaller will include it automatically : to be tested.
--add-data "*.csv;." ^
--add-data "AudioSamples;AudioSamples" ^
Both these lines are specific to my experiment : these are files that are loaded at runtime.
.\sound_test.py
Finally, this is the Python file that is compiled in the PsychoPy builder.
Important note : I could never figure out how to make the ioHub backend work for input purposes, so I had to switch to Psychtoolbox in the Experiment settings in the PsychoPy builder.
I hope this will help some people in my situation. And by the way, thanks for the awesome software !