I want to use Pytorch and OpenCV in Pycharm. So I created a virtual conda env and installed some packages to use.
When I execute Python in the Windows terminal and import torch and cv2, it worked well.
(Pytorch) C:\Users\choib>python
Python 3.7.1 | packaged by conda-forge | (default, Nov 13 2018, 19:01:41) [MSC v.1900 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> import torch
>>>
It does not work normally with Pycharm. If I import cv2
before torch
or torchvision
or without them, it raises an error.
Example
import cv2 as cv
import torch
Result
D:\program\anaconda3\envs\pytorch\python.exe C:/Users/choib/Desktop/YOLO_01/YOLO_image.py
Traceback (most recent call last):
File "C:/Users/choib/Desktop/YOLO_01/YOLO_image.py", line 1, in <module>
import cv2 as cv
ImportError: DLL load failed: The specified module could not be found.
But if I import cv2
after torch
or torchvision
, it has no problem.
As a result, I don't have any problem to execute my code. But I wonder why I need to import torch or torchvision unnecessarily to avoid this ImportError.