About import numpy in PyCharm appears from . import _mklinit ImportError: DLL load failed: The specified module cannot be found

Recently installed Anaconda3 for some reason and reconfigured the Python environment, but encountered some troubles.

The first is that when Anaconda has installed numpy and mkl, import numpy in PyCharm, it will prompt

from . import _mklinit ImportError: DLL load failed: The specified module could not be found

But numpy can be imported correctly in Jupiter and Spider, and this problem will not occur.

I have found a lot of solutions on the Internet (most of them are caused by problems such as the mismatch between the python version and the numpy version, and need to be reinstalled), but they have tried to no avail. Finally found the answer in this article https://www.jianshu.com/p/2418311bbad0.

Because I used to install python directly and did not use Anaconda's python, I remembered after reading this article that the original python path was kept in the environment variable, and the Anaconda path was not added. The problem after adding the following path to the PATH That's it.

Of course, I have also seen some articles (including tips when Anaconda is installed) saying that it is not recommended to add Anaconda to the environment variable, but if you don't add it to the environment variable, it seems that there is no way to solve the problem that numpy cannot be imported in PyCharm. The specific reason I It's not very clear, I don't know if there is a better way, I hope everyone can put it forward, thank you.

In the process of environment configuration, I also encountered another problem, that is, after the above problem was solved, I found that another prompt appeared.

Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll. 

At first I thought it was related to the installation process of mkl, so I uninstalled and reinstalled mkl but it didn't solve the problem.

Until I saw this article https://blog.csdn.net/Steven19920104/article/details/90900470, it may be because the related dll files are not found by the program, so you need to put libiomp5md.dll in the Anaconda directory Copied to C:\Windows\System32, it seems to be able to find the mkl_intel_thread.dll file in the environment.

As can be seen from the figure below, the mkl_intel_thread.dll file does exist in the environment, but it is not read by the program.

All in all, I am very grateful to the authors of these two blogs for helping me solve these two problems. I also record these two questions here as a reference for anyone who encounters the same problem.

Related Posts