在AWS深度学习AMI上安装scikit-learn遇ModuleNotFoundError问题求助
It looks like the issue comes down to installing scikit-learn in the wrong Conda environment—you installed it somewhere that doesn’t match the environment your Jupyter Notebook is running from. Let’s walk through fixing this:
Step 1: Check your Conda environments and scikit-learn’s location
First, list all your Conda environments to see which one you’re using and where scikit-learn might be installed:
conda env list
You’ll see a list of environments (like base, python3, or AWS-specific ones) with an * next to the currently active one.
Next, verify if scikit-learn is installed in the python3 environment you activated:
conda list -n python3 scikit-learn
If scikit-learn doesn’t show up here, that’s the problem—you probably installed it into the base environment instead, but Jupyter is running from python3.
Step 2: Install scikit-learn in the correct environment
Activate the python3 environment first, then install scikit-learn directly into it:
# For older Conda versions source activate python3 # For Conda 4.4+ conda activate python3 # Install scikit-learn into the active python3 environment conda install -c anaconda scikit-learn
Step 3: Restart Jupyter and test
Close your existing Jupyter Notebook session, restart it with jupyter notebook, and re-run your import code. The ModuleNotFoundError should disappear once scikit-learn is available in the environment Jupyter is using.
Alternative: Use the base environment (if you prefer)
If you’d rather stick with the base environment where scikit-learn is already installed:
- Activate the base environment:
source activate base # or conda activate base - Make sure Jupyter is installed in base:
conda install jupyter - Launch Jupyter from the base environment, and select the
basekernel when creating a new notebook.
内容的提问来源于stack exchange,提问作者Garglesoap

