Hi,
I have been trying to import psychopy with something like import psychopy as psp
. Although this doesn’t flag an error, but I am unable to use any submodules or associated functions. E.g., running
unique_conditions = psp.data.importConditions(
fileName="./conditions.xlsx",
)
gives me:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 unique_conditions = psp.data.importConditions(
2 fileName="./conditions.xlsx",
3 )
5 unique_conditions
AttributeError: module 'psychopy' has no attribute 'data'
I am, however, able to use the modules by importing them individually. E.g., from psychopy import data
works. I was wondering if I am doing something silly here? If not, would anyone know why aliased importing is not supported ?
Cheers
I learned some things about Python and PsychoPy today.
It’s not the aliasing, you’d get the same issue by using ‘import psychopy’ and then trying to refer to psychopy.data
It’s something about the structure of how PsychoPy is set up. You can’t actually just ‘import psychopy’ and refer to the sub-modules like they’re attributes of a psychopy module. They’re actually separate modules that need to be initialized, so they need to be imported separately. So you can call ‘import psychopy.data’ and it will initialize the data module correctly, same as ‘from psychopy import data’, and you can give an alias to the sub-module (from psychopy import data as psp.data), but it looks like you can’t just import psychopy and then refer to all the sub-modules as attributes of the larger whole on the fly. I’m not sure why it works that way, but that seems to be the root issue.
Hi,
Thank you for the in-depth reply. Curious indeed. I guess a possible reason might be that loading the entire psychopy ecosystem at once might be too heavy for some older processors.
Cheers