| Reference | Downloads | Github

Sklearn module imports in shell but not in script

Hello everyone,

I’m using PsychoPy 3.0.7 on macOS Mojave 10.14.5, and am having trouble importing sklearn from my anaconda site packages folder. I’ve created a .pth file with the necessary file path and added it to my PsychoPy site packages folder. Running ‘import sklearn’ in the PsychoPy coder shell executes successfully, and I’m able to call functions in the shell; however, this same line of code throws a ModuleNotFoundError when executed (in the PsychoPy coder) as part of this script:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sklearn 

My problem is almost identical to this post:

…but the solutions proposed there are not working for me (e.g., I have verified that the script and shell are using the same python version).

In lieu of the above strategy, I’ve made several failed attempts at pip installing sklearn in the PsychoPy site packages directory, all ending with the message that sklearn “has not been built correctly.” I also tried installing PsychoPy in anaconda (see here, again without success. These sagas probably deserve their own post, but for now I’m focusing on my conda installation of sklearn, since I can at least import it using the shell.

I would be very grateful to anyone who might be able to help me here!