PsychoPy version 2022.2.5 - but have changed version to 2021.2.3 in Experiment Settings due to compatibility issues with the desired external module
**Standard Standalone? y
What are you trying to achieve?:
I would like to insert the following code chunk into a routine in the builder so that I can run some trials from the Heart Rate Discrimination task in my experiment. The Heart Rate Discrimination task is available using the external “cardioception” module
from cardioception.HRD.parameters import getParameters from cardioception.HRD import task # Set global task parameters parameters = getParameters( participant='Subject_01', session='Test', serialPort=None, setup='test', nTrials=10, screenNb=0) # Run task task.run(parameters, confidenceRating=True, runTutorial=True) parameters['win'].close()
I got this code from the cardioception module GitHub page and it should run 10 trials of the Heart Rate Discrimination task.
What did you try to make it work?:
I used pip install within a virtual environment I created in Anaconda to install the “cardioception” module and all its dependencies. When I run the above code within the environment it works perfectly. But when I tried to do it from within the PsychoPy builder it couldn’t find the module, so I updated the preferences in PsychoPy to add the site-packages folder created in the virtual environment to path. This allowed PsychoPy to find the cardioception module, however, it then started to give the following error message:
## Running: C:\Users\Carmen Daoust\Desktop\Experiment_Master\PsychoPy2_exp\untitled_lastrun.py ## 3183.1054 INFO Loaded monitor calibration from ['2023_01_20 18:47'] pygame 2.1.0 (SDL 2.0.16, Python 3.8.10) Traceback (most recent call last): Hello from the pygame community. https://www.pygame.org/contribute.html 2.3362 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['sounddevice', 'pyo', 'pygame'] (in that order). 4.3786 WARNING User requested fullscreen with size [1024 768], but screen is actually [1920, 1080]. Using actual size File "C:\Users\Carmen Daoust\Desktop\Experiment_Master\PsychoPy2_exp\untitled_lastrun.py", line 203, in <module> from cardioception.HRD.parameters import getParameters File "C:\Anaconda\envs\experiment_env_3716\Lib\site-packages\cardioception\__init__.py", line 4, in <module> from .HBC import * File "C:\Anaconda\envs\experiment_env_3716\Lib\site-packages\cardioception\HBC\__init__.py", line 1, in <module> from .parameters import * File "C:\Anaconda\envs\experiment_env_3716\Lib\site-packages\cardioception\HBC\parameters.py", line 11, in <module> from systole import serialSim File "C:\Anaconda\envs\experiment_env_3716\Lib\site-packages\systole\__init__.py", line 3, in <module> from .correction import * File "C:\Anaconda\envs\experiment_env_3716\Lib\site-packages\systole\correction.py", line 8, in <module> from systole.detection import rr_artefacts File "C:\Anaconda\envs\experiment_env_3716\Lib\site-packages\systole\detection.py", line 7, in <module> from ecgdetectors import Detectors File "C:\Anaconda\envs\experiment_env_3716\Lib\site-packages\ecgdetectors.py", line 11, in <module> import pywt File "C:\Anaconda\envs\experiment_env_3716\Lib\site-packages\pywt\__init__.py", line 15, in <module> from ._extensions._pywt import * ModuleNotFoundError: No module named 'pywt._extensions._pywt'
I thought adding the pywt folder specifically to path in preferences might help, but it didn’t make any difference so I removed it. I have also tried adding a .pth file to Program files\PsychoPy\Lib\site-packages with C:\Anaconda\envs\experiment_env_3716\Lib\site-packages as the path, but this didn’t seem to work either.
This is my first experience trying to build an experiment or use Python, so I’m not sure if I’m making a really obvious mistake - but any advice would be much appreciated!