I have found one solution but not perfect for this kind of problem. I hope the next version of pytorch can fix such problem.
We write a script called “main.py 2”, in which we use the pytorch but without opencv. And as for opencv operation, we are mainly aimed to process data, so I create another script called “datautils.py 1”, in which we import opencv without using any operation in pytorch.
In order to get the data from datautils.py 1, we can take measures as following. For example
in main.py 2
import torch
# some operation in torch
from subprocess import PIPE,Popen
import pickle
p = Popen('python datautils.py ' + argv, shell=True, stdout=PIPE, stderr=PIPE)
out,err = p.communicate()
data = pickle.loads(out)
# some operation in torch

In datautils.py 1
import cv2
import pickle
if __name__ == "__main__":
    cap = cv2.VideoCapture(argv[1])
    has_next, img = cap.read()
    # and some other operation in cv2
    print(pickle.dumps(data))

It works in debian.