Unable to load shared library 'MklImports' or one of its dependencies.
System information
- Mac 0S Mojave 10.14.3:
- dotnet --version 2.2.300
- Project references
- Microsoft.ML
- Microsoft.ML.Mkl.Redis
- Microsoft.ML.TimeSeries
Issue
-
Possible that this is of the same origin as #3694 but in case it is a separate case I have posted this issue.
-
What did you do? Followed new forecasting tutorial for ML.Net 1.1 https://github.com/dotnet/machinelearning/blob/master/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/Forecasting.cs
-
What happened? Dll not found exception
-
What did you expect? Program to run successfully
Source code / logs
Unable to load shared library 'MklImports' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libMklImports, 1): image not found
at Microsoft.ML.Transforms.TimeSeries.EigenUtils.Dsytrd(Layout matrixLayout, Uplo uplo, Int32 n, Double[] a, Int32 lda, Double[] d, Double[] e, Double[] tau)\n at Microsoft.ML.Transforms.TimeSeries.EigenUtils.MklSymmetricEigenDecomposition(Single[] input, Int32 size, Single[]& eigenValues, Single[]& eigenVectors)\n at Microsoft.ML.Transforms.TimeSeries.TrajectoryMatrix.ComputeSvd(Single[]& singularValues, Single[]& leftSingularvectors)\n at Microsoft.ML.Transforms.TimeSeries.AdaptiveSingularSpectrumSequenceModeler.AdaptiveSingularSpectrumSequenceModelerInternal.TrainCore(Single[] dataArray, Int32 originalSeriesLength)\n at Microsoft.ML.Transforms.TimeSeries.AdaptiveSingularSpectrumSequenceModeler.AdaptiveSingularSpectrumSequenceModelerInternal.Train(RoleMappedData data)\n
I'm seeing the same thing using Microsoft.ML.TimeSeries 1.3.1 on Windows 10 Enterprise, with a library targeting net48;netstandard2.0 and a unit test project targeting net48.
System.TypeInitializationException : The type initializer for 'Microsoft.ML.Transforms.TimeSeries.FftUtils' threw an exception.
----> System.DllNotFoundException : Unable to load DLL 'MklImports': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Microsoft.ML.Transforms.TimeSeries.FftUtils.ComputeForwardFft(Single[] inputRe, Single[] inputIm, Single[] outputRe, Single[] outputIm, Int32 length)
at Microsoft.ML.Transforms.TimeSeries.SrCnnAnomalyDetectionBase.SrCnnAnomalyDetectionBaseCore.State.SpectralResidual(Single input, FixedSizeQueue`1 data, VBufferEditor`1& result)
at Microsoft.ML.Transforms.TimeSeries.SrCnnTransformBase`2.SrCnnStateBase.TransformCore(TInput& input, FixedSizeQueue`1 windowedBuffer, Int64 iteration, VBuffer`1& dst)
at Microsoft.ML.Transforms.TimeSeries.SequentialTransformerBase`3.StateBase.Process(TInput& input, TOutput& output)
at Microsoft.ML.Transforms.TimeSeries.SrCnnTransformBase`2.Mapper.<>c__DisplayClass16_0.<MakeGetter>b__0(VBuffer`1& dst)
at Microsoft.ML.Data.TypedCursorable`1.TypedRowBase.<>c__DisplayClass8_0`1.<CreateDirectVBufferSetter>b__0(TRow row)
at Microsoft.ML.Data.TypedCursorable`1.TypedRowBase.FillValues(TRow row)
at Microsoft.ML.Transforms.TimeSeries.TimeSeriesPredictionEngine`2.Predict(TSrc example, TDst& prediction, Nullable`1 horizon, Nullable`1 confidenceLevel)
at Microsoft.ML.Transforms.TimeSeries.TimeSeriesPredictionEngine`2.Predict(TSrc example, Nullable`1 horizon, Nullable`1 confidenceLevel)
I've tried the sample in VS 2017 community on Windows 7 and 10 (dotnet 2.1) at last weekend. It seems it worked without problem.
Still having issue on Mac.
ML.net 1.4 / Docker container with Ubuntu 16.04 .net core 3.0
Works find debugging locally on Windows, but deploying it to Ubuntu container throws the error intermittently. Half the time it works, half the time it throws the error. It's not random and throws on certain data sets.
System.DllNotFoundException: Unable to load shared library 'MklImports' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libMklImports: cannot open shared object file: No such file or directory
web_1 | at Microsoft.ML.Transforms.TimeSeries.EigenUtils.Dsytrd(Layout matrixLayout, Uplo uplo, Int32 n, Double[] a, Int32 lda, Double[] d, Double[] e, Double[] tau)
web_1 | at Microsoft.ML.Transforms.TimeSeries.EigenUtils.MklSymmetricEigenDecomposition(Single[] input, Int32 size, Single[]& eigenValues, Single[]& eigenVectors)
web_1 | at Microsoft.ML.Transforms.TimeSeries.TrajectoryMatrix.ComputeSvd(Single[]& singularValues, Single[]& leftSingularvectors)
web_1 | at Microsoft.ML.Transforms.TimeSeries.AdaptiveSingularSpectrumSequenceModelerInternal.TrainCore(Single[] dataArray, Int32 originalSeriesLength)
web_1 | at Microsoft.ML.Transforms.TimeSeries.AdaptiveSingularSpectrumSequenceModelerInternal.Train(RoleMappedData data)
web_1 | at Microsoft.ML.Transforms.TimeSeries.SsaForecastingTransformer..ctor(IHostEnvironment env, Options options, IDataView input)
web_1 | at Microsoft.ML.Transforms.TimeSeries.SsaForecastingEstimator.Fit(IDataView input)
web_1 | at Veritas_Web.Utilities.MLTSVFile.ForcastWithTime(Int32 size, IDataView dataView) in /src/Utilities/MLTSVFile.cs:line 211
Same issue on .NET Core 3.1
Version: 3.1.101 Runtime Environment: OS Name: Mac OS X OS Version: 10.15 OS Platform: Darwin RID: osx.10.15-x64 Base Path: /usr/local/share/dotnet/sdk/3.1.101/
Exception has occurred: CLR/System.DllNotFoundException An unhandled exception of type 'System.DllNotFoundException' occurred in Microsoft.ML.TimeSeries.dll: 'Unable to load shared library 'MklImports' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libMklImports, 1): image not found'
@hectorcubillos and everyone else, I was able to get this fixed
Make sure you have the Microsoft.ML.Mkl.Redist nuget package for the project you are attempting to run. For example, right click the C# project in Solution Explorer > Manage Nuget Packages then search for "mkl" and install Microsoft.ML.Mkl.Redist then rebuild your project.
@mphollas @ilias @flo8 @eduardobr @Benzidrine @archeg @dhunt84971 @lessenko @todarko @hectorcubillos
First of all, apologies that it took us this long to get to this. I have begun taken a look at this and here's what I have found so far:
-
On macOS 10.14.16, I could not reproduce this issue at all. I used .NET Core 2.2.300, which is the most frequently cited version here. I did the following with both Visual Studio for Mac and the
dotnetcommand line: I copied the code from the forecasting sample linked by OP into a new .NET Core console project, then built and ran the project with ML.NET 1.1, 1.2, 1.3.1, 1.4, 1.5.0-preview2. In all 2x5=10 attempts, I could not reproduce the error. If one of you could provide me with the smallest .NET Core project that can reproduce this, along with details about your environment, I could investigate further. -
I was able to reproduce this on Ubuntu 18.04 with both .NET Core 2.2.300 and 3.1.200. I created a new project with the
dotnetcommand line, and followed the same steps as for macOS above. The issue was reproduced for all five versions of ML.NET withdotnet run. The native dlls were not present inbin/Debug/netcoreapp2.2, and withdotnet publish, not copied intobin/Debug/netcoreapp2.2/publishfolder. This persisted even after addingNativeAssemblyReferenceto the project.@eerhardt does this situation look familiar to you? Here are the contents of my
.csprojfile:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ML" Version="1.2" />
<PackageReference Include="Microsoft.ML.Mkl.Redist" Version="1.2" />
<PackageReference Include="Microsoft.ML.TimeSeries" Version="1.2" />
<NativeAssemblyReference Include="CpuMathNative" />
<NativeAssemblyReference Include="FastTreeNative" />
<NativeAssemblyReference Include="MatrixFactorizationNative" />
<NativeAssemblyReference Include="LdaNative" />
<NativeAssemblyReference Include="SymSgdNative" />
<NativeAssemblyReference Include="MklProxyNative" />
</ItemGroup>
</Project>
cc: @harishsk
@najeeb-kazmi Is your project part of ML.NET sources or a standalone project? Can you turn on verbose logging in your msbuild and see if the logging has any mention of trying to copy these files?
If your project is a standalone project I suspect they aren't being copied over because they are missing the CopyNativeAssemblies target that is present in Directory.Build.Targets in ML.NET.
NativeAssemblyReference is internal to the dotnet/machinelearning repo. This isn't something that users would ever use. We only do it in our repo to get native assemblies placed in our bin directory.
For anyone who is running into this issue on a mac, there are 2 things I can recommend.
- To try to debug why this is happening, the exception message says
In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libMklImports, 1). Consider doing this and sharing the output. It would help figure out what is going wrong. - An option to try to fix it is to install libomp on the machine. This is what we do on our CI servers:
brew update && brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f5b1ac99a7fba27c19cee0bc4f036775c889b359/Formula/libomp.rb && brew link libomp --force
It appears that the tests and samples in the ML.NET repo are relying on NativeAssemblyReference to make sure that the native assemblies are copied over. Since this facility is not available outside the repo, what is our recommendation to developers taking a dependency on the nugets directly for making sure that the native assemblies are copied over?
what is our recommendation to developers taking a dependency on the nugets directly for making sure that the native assemblies are copied over?
They reference our nuget packages, and the .NET tooling (NuGet, MSBuild) copies the native assemblies correctly.
On Ubuntu 16.04 and 18.04, in my standalone project with Microsoft.ML.Timeseries nuget, libMklmports.so is present in /bin/Debug/netcoreapp3.1/runtimes/linux-x64/native, but it has a dependency on libiomp5.so, which is not found. Following the instructions here, I installed MKL, where in the "How do I install a particular version?", I installed the latest version for my 64 bit distro:
$ sudo apt-get install intel-mkl-64bit-2020.0-088
This installs libiomp in /opt/intel. Then, the location where libiomp5 gets installed:
$ find /opt -name "libiomp5.so"
/opt/intel/compilers_and_libraries_2020.0.166/linux/compiler/lib/intel64_lin/libiomp5.so
needs to be added to the load library path:
$ sudo ldconfig /opt/intel/compilers_and_libraries_2020.0.166/linux/compiler/lib/intel64_lin/
After this, I can run my console app without an error.
On the other hand, on macOS 10.14.6, the libraries are present:
dyld: loaded: /Users/admin/.nuget/packages/microsoft.ml.mkl.redist/1.5.0-preview2/runtimes/osx-x64/native/libMklImports.dylib
dyld: loaded: /usr/local/lib/libiomp5.dylib
On Windows, the dll gets copied to and loaded from \bin\Debug\netcoreapp3.0\runtimes\win-x64\native\libiomp5md.dll.
So the root cause is that libMklImports depends on OpenMP library libiomp5. Because of redistribution licensing reasons, libiomp5.dll is packaged in the ML.NET nugets for Windows only. libiomp5.dylib and libiomp5.so are not packaged for MacOS and Linux, respectively. If these libraries are not already present on the system, this error will be thrown.
Note: libMklImports itself is packaged for Windows, MacOS, and Linux.
For now, the solution is to install the library directly. We will make a decision on whether to get redistribution licensing for libiomp5, and decide where to document this in the meantime.
MacOS
Install libiomp5 version 7 specifically.
brew update && brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f5b1ac99a7fba27c19cee0bc4f036775c889b359/Formula/libomp.rb && brew link libomp --force
This should download the library to /usr/local/lib/libiomp5.dylib, from where it should be loaded without an issue.
Linux
Install MKL, which will install libiomp.so, following the instructions here, specifically these steps:
Install the GPG key for the repository:
sudo bash
# <type your user password when prompted. this will put you in a root shell>
# cd to /tmp where this shell has write permission
cd /tmp
# now get the key:
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB
# now install that key
apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB
# now remove the public key file exit the root shell
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB
exit
Add the APT Repository for MKL:
sudo sh -c 'echo deb https://apt.repos.intel.com/mkl all main > /etc/apt/sources.list.d/intel-mkl.list'
Update packages:
sudo apt-get update
Install MKL:
sudo apt-get install <COMPONENT>-<VERSION>.<UPDATE>-<BUILD_NUMBER>
For example:
sudo apt-get install intel-mkl-64bit-2020.0-088
This installs libiomp.so in /opt/intel. Find the exact location:
find /opt -name "libiomp5.so"
/opt/intel/compilers_and_libraries_2020.0.166/linux/compiler/lib/intel64_lin/libiomp5.so
Add this location to the load library path:
sudo ldconfig /opt/intel/compilers_and_libraries_2020.0.166/linux/compiler/lib/intel64_lin/
These additional steps have been documented here: https://docs.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/install-extra-dependencies
Hi guys! Is there any way to fix it for Windows? Running the app in Docker windows image
I have installed all required nuget packages (Microsoft.ML.TimeSeries, Microsoft.ML.AutoML) but still the same error =(... any suggestion @najeeb-kazmi ?
I'm getting this error too using DetectSpikeBySsa in VS2019 on Windows 10 (C#) - I have the Microsoft.ML.Mkl.Redist NuGet installed.

I am getting 'Unable to load DLL 'MklImports' or one of its dependencies' while calling Fit method of ForecastBySsa() in a time series prediction.
The issue surfaced in Jupyter notebook only, the same code runs fine in Visual Studio 2019.
OS: Windows 10 x64 .Net core: 3.1.300 Microsoft.ML : 1.5.0 Microsoft.ML.TimeSeries : 1.5.0 Visual Studio 2019 16.6.0
Logs
SubmitCode: var model = pipeline.Fit(data);
CodeSubmissionReceived: var model = pipeline.Fit(data);
CompleteCodeSubmissionReceived: var model = pipeline.Fit(data);
System.DllNotFoundException: Unable to load DLL 'MklImports' or one of its dependencies: The specified module could not be found. (0x8007007E)
at Microsoft.ML.Transforms.TimeSeries.EigenUtils.Dsytrd(Layout matrixLayout, Uplo uplo, Int32 n, Double[] a, Int32 lda, Double[] d, Double[] e, Double[] tau)
at Microsoft.ML.Transforms.TimeSeries.EigenUtils.MklSymmetricEigenDecomposition(Single[] input, Int32 size, Single[]& eigenValues, Single[]& eigenVectors)
at Microsoft.ML.Transforms.TimeSeries.TrajectoryMatrix.ComputeSvd(Single[]& singularValues, Single[]& leftSingularvectors)
at Microsoft.ML.Transforms.TimeSeries.AdaptiveSingularSpectrumSequenceModelerInternal.TrainCore(Single[] dataArray, Int32 originalSeriesLength)
at Microsoft.ML.Transforms.TimeSeries.AdaptiveSingularSpectrumSequenceModelerInternal.Train(RoleMappedData data)
at Microsoft.ML.Transforms.TimeSeries.SsaForecastingTransformer..ctor(IHostEnvironment env, Options options, IDataView input)
at Microsoft.ML.Transforms.TimeSeries.SsaForecastingEstimator.Fit(IDataView input)
at Submission#30.<
These additional steps have been documented here: https://docs.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/install-extra-dependencies
The documentation is clear, however it does not work for me. I get the following exception when calling DetectSpikeBySsa
System.TypeInitializationException: 'The type initializer for 'Microsoft.ML.Transforms.TimeSeries.FftUtils' threw an exception.'
DllNotFoundException: Unable to load shared library 'MklImports' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libMklImports: cannot open shared object file: No such file or directory
when I run find /opt -name "libiomp5.so" , I get: /opt/intel/compilers_and_libraries_2020.0.166/linux/compiler/lib/intel64_lin/libiomp5.so - so the installation is successfull.
And one little comment about the exception: the LD_DEBUG env variable does not have a lib option, it's libs
I use the mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim container.
Please, let me know what I can do in order to resolve this problem. Thank you for your kind help.
@danielleiszen did you add libiomp path to the load library path like below?
sudo ldconfig /opt/intel/compilers_and_libraries_2020.0.166/linux/compiler/lib/intel64_lin
you can verify this by check the "LD_LIBRARY_PATH" variable