简体   繁体   中英

Why can't I import cv2 from anywhere else than install dir?

I'm using anaconda with spyder on Win 10. I installed opencv by pip-install opencv-python. If I do

import cv2

in the default directory (C:\\ProgramData\\Anaconda3), it will work. However, if I do the same command anywhere else I'll have an error :

import cv2
Traceback (most recent call last):

  File "<ipython-input-3-c8ec22b3e787>", line 1, in <module>
    import cv2

ImportError: DLL load failed: Le module spécifié est introuvable.

If I want to run a script which needs cv2, I have to go in C:\\ProgramData\\Anaconda3 , then import cv2 and finally run my script in whatever directory I want. I don't have this problem with other modules, like pygame or pillow.

This may be because the IDE may contain many Interpreter and the cv2 library is not installed for the python Interpreter which is set for the system, try to install the cv2 with command prompt using pip install opencv-python . then it may work for you from any location.

Ok, thanks to Abhishek-Saini. Following this video where pip directory is added to PATH , I added C:\\opencv\\build\\x64\\vc15\\bin to path. And, it works ! (for now, then)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM