Last updated: Apr 13, 2024
Reading time·3 min
The Python error "OMP: Error #15: Initializing libiomp5md.dll, but found mk2iomp5md.dll already initialized" occurs when you have conflicting installations of packages.
To solve the error, set the KMP_DUPLICATE_LIB_OK
environment variable to
True
.
Here is the complete error message.
The kernel (user Python environment) has terminated with error code 3. This may be due to a bug in your code or in the kernel itself. Output captured from the kernel process is shown below. OMP: Error #15: Initializing libiomp5md.dll, but found mk2iomp5md.dll already initialized. OMP: Hint: This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
KMP_DUPLICATE_LIB_OK
environment variable in your Python scriptOne way to solve the error is to set the KMP_DUPLICATE_LIB_OK
environment
variable to the string "True"
in the Python script in which the error occurs.
import os os.environ['KMP_DUPLICATE_LIB_OK'] = 'True' # The rest of your code below
We used the os.environ
mapping object to set the KMP_DUPLICATE_LIB_OK
environment variable to the
string "TRUE"
.
Make sure to place the two lines at the top of the Python script in which the error occurred (above any other import statements).
If you set the environment variable after the rest of your code runs, it won't have an effect.
KMP_DUPLICATE_LIB_OK
environment variable in your shellAlternatively, you can set the KMP_DUPLICATE_LIB_OK
environment variable in
your shell.
If you are on macOS or Linux, open bash
or zsh
and issue the following
command.
# For macOS and Linux export KMP_DUPLICATE_LIB_OK=True
If you are on Windows and use Command Prompt (CMD), run the following command.
# For Windows Command Prompt set KMP_DUPLICATE_LIB_OK=True
If you are on Windows and use PowerShell, run the following command instead.
# For Windows PowerShell $env:KMP_DUPLICATE_LIB_OK=1
Try to rerun your Python script after setting the KMP_DUPLICATE_LIB_OK
environment variable.
If you got the error when using Anaconda, try to install the nomkl package.
conda install nomkl --channel conda-forge
Then run the following command.
conda install numpy scipy pandas tensorflow
And finally, remove the mlk
package.
conda remove mkl mkl-service
If the error persists after running the command, try to recreate your virtual environment.
conda deactivate # Rerun the installation command conda install nomkl --channel conda-forge
conda create --name my-env
conda activate my-env
Make sure to replace the my-env
placeholder with your preferred virtual
environment name.
conda install -c anaconda numpy
If the error persists and you use Anaconda, try to rename/delete the
libiomp5md.dll
.
The file should be located in one of these directories:
~/anaconda3/lib/libiomp5md.dll
~/anaconda3/Library/bin/libiomp5md.dll
~/anaconda3/envs/YOUR_ENV_NAME/Library/bin/libiomp5md.dll
C:\Users\YOUR_USER\Anaconda3\envs\YOUR_ENV_NAME\Library\bin\libiomp5md.dll
If you don't know where Anaconda is installed, issue the where conda
command.
where conda
If you don't want to delete the libiomp5md.dll
file, simply rename it to
something else to have a backup.
You can learn more about the related topics by checking out the following tutorials: