Installing packages

I’m currently trying to run an experiment in the 2021.2.3 version of PsychoPy, and I need to import the packages “scikit-learn” and the submodule “hmm” from “hmmlearn” to make it run properly. I spent a whole day trying to make this work, but I couldn’t find a solution. Even if I seeminly manage to import the package, I can’t access the submodules.

This is what I tried (I’m using macOS Monterey 12.0.1 btw):

First I tried pip installing the packages in the following directory:
and then importing them as usual (i.e. with import sklearn for example). This didn’t work.

Then I tried downloading the latest version of the package that was still compatible with Python 3.6.9, added it to the PsychoPy package library here:
and imported it as usual. This didn’t work, so I renamed the package (from scikit-learn-0.24.2 to scikit_learn) and imported it by its folder name using the importlib package:

import importlib
package_name = 'scikit_learn'
sklearn = importlib.import_module(package_name)

At first glance, this seemed to work, but when I checked whether I could actually use the package, I got an error message telling me “ModuleNotFoundError: No module named ‘sklearn’”. This was my test case:

from sklearn.datasets import load_iris
data = load_iris()
print("Number of samples:", len(

Then I downloaded the package as a .whl file and added a path to the folder where I put it in Preferences > General > paths. This also didn’t work.

I also wanted to try the .pth approach described here, but didn’t really understand what I’m supposed to do.

I would be really happy if someone could give me a hint on how to make this work, I’m really stuck right now. :cold_sweat: