[Solved] Importerror: DLL load failed while importing mtrand: the specified program could not be found.

Problems encountered in the early stages of OpenCV learning
ImportError: DLL load failed while importing mtrand: The specified program could not be found.
After reinstalling python, I still couldn’t use it, and then I found out many times that the problem was caused by the wrong version of python.
After trying python 3.9, python 3.6, python 3.8 and a series of other versions, I found that the same problem was still reported.

    "E:\specialize software\Python3.9\python.exe" E:/Workspace/untitled1/venv/openvtest.py
OpenCV bindings requires "numpy" package.
Install it via command:
    pip install numpy
Traceback (most recent call last):
  File "E:\Workspace\untitled1\venv\openvtest.py", line 1, in <module>
    import cv2
  File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\cv2\__init__.py", line 11, in <module>
    import numpy
  File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\numpy\__init__.py", line 161, in <module>
    from . import random
  File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\numpy\random\__init__.py", line 180, in <module>
    from . import _pickle
  File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\numpy\random\_pickle.py", line 1, in <module>
    from .mtrand import RandomState
ImportError: DLL load failed while importing mtrand: The specified program could not be found.

After a series of attempts, it is finally found that Anaconda 3-5.3.1 can adapt to opencv Python and numpy packages. If the problem appears, this error indicates that opencv Python and numpy have been PIP before, so I won’t repeat here. The installation methods of CV2 and numpy are everywhere. If not, please ask Du Niang.

The following is the image download website of Anaconda 3-5.3.1

https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

After downloading, you can install it directly. Be careful not to install it on disk C

No error is reported after importing CV2 and numpy again using anaconda

import numpy
import cv2

if __name__ == '__main__':
    print('Success')
"E:\specialize software\Anaconda\python.exe" E:/Workspace/untitled1/venv/openvtest.py
Success

Process has ended, exit code 0

Similar Posts: