An import sklearn statement fails with an Unhandled Python exception


The SAS® Viya® platform can install Python packages using the SAS® Configurator for Open Source. After upgrading to a new SAS Viya version prior to Stable 2026.07 or re-running the sas-pyconfig job, a Python program that imports the sklearn package fails with an exception:

ERROR: Unhandled Python exception.
>>>
<string>:3: UserWarning: A NumPy version >=2.0.0 and <2.8.0 is required for this version of SciPy (detected version 1.26.4)

Cause

The Python packages installed by the sas-pyconfig job are specified in the change-configuration.yaml file. You can pin a package to a specific version.

In previous version of SAS Viya, the numpy package was pinned to the 1.26.4 version. However, the SciPy packages are not pinned. Newer versions of the SciPy package require a version of numpy greater than 1.26.4.

Resolution