Fix SciPy and scikit-learn import errors in VS Code notebooks

Published · Updated

Save

Identify the Python executable used by the notebook before changing dependencies. When the terminal and notebook use different environments, reinstalling packages in the terminal may leave the notebook unchanged.

Identify the notebook environment

In a notebook cell, run import sys; print(sys.executable). Compare that path with the environment you expect. Select the matching VS Code notebook kernel and restart it after dependency changes.

Install a compatible set

In the intended environment, use its Python executable with -m pip. For a new pip environment, install scikit-learn and let its dependency metadata resolve NumPy and SciPy together. For an existing project, use its requirements or lockfile and check for conflicts with python -m pip check.

Verify the imports in the notebook

Run import scipy, sklearn and print their versions. For an internal-module error, identify which installed package imports the missing symbol, then update or reproduce that package's documented compatible environment. Avoid guessing an old SciPy version from the exception alone.

References

scikit-learn installation and dependencies

VS Code Jupyter kernels

pip check

Discuss this answer