Question
Running a cell in a Jupyter notebook (for example, a scikit-learn KMeans clustering) prints warning messages below the cell, such as:
- a
threadpoolctlRuntimeWarningreporting that Intel OpenMP (libiomp) and LLVM OpenMP (libomp) are loaded at the same time - a scikit-learn
UserWarningthatKMeanshas a known memory leak on Windows with MKL
How can these warning messages be hidden?
Answer
These messages are produced by the Python libraries being imported and executed (such as scikit-learn and threadpoolctl), not by PyCharm. When a notebook cell runs, the IDE displays whatever the code writes to standard output and standard error, including warnings emitted through Python's warnings module. The same messages appear in any Jupyter frontend, so they are controlled from Python rather than from an IDE setting.
Hide the warnings
Add the following to the first cell of the notebook, before the imports that trigger the warnings:
import warnings
warnings.filterwarnings("ignore")
To suppress only specific categories instead of all warnings:
import warnings
warnings.filterwarnings("ignore", category=UserWarning)
warnings.filterwarnings("ignore", category=RuntimeWarning)
Address the scikit-learn KMeans warning at its source
The KMeans memory-leak UserWarning on Windows with MKL can be avoided by setting the OMP_NUM_THREADS environment variable to 2. The variable must be set before NumPy is imported, so place it at the top of the first cell and restart the kernel afterward:
import os
os.environ["OMP_NUM_THREADS"] = "2"
Resolve the OpenMP conflict warning
The threadpoolctl RuntimeWarning about Intel OpenMP and LLVM OpenMP being loaded at the same time indicates that two OpenMP runtimes are present in the Python environment. This is common in Conda environments that mix packages from different channels. The warning filter above hides the message. To remove the cause, reinstall NumPy, scikit-learn, and any package that bundles its own OpenMP runtime from the same Conda channel so that only one OpenMP runtime loads.
Comments
0 comments
Please sign in to leave a comment.