0
votes

When I tried to import torchvision, I got an import error.

I googled this problem but found nothing except that the problem may be in Cython. StackOverflow search didn't found anything either. How can I solve this?

Torchvision version is 0.3.0.

import torchvision

Traceback (most recent call last): File "/home/ai/PycharmProjects/untitled/TRANSFER.py", line 4, in import torchvision File "/home/ai/anaconda3/envs/reinforcement/lib/python3.5/site-packages/torchvision/init.py", line 1, in from torchvision import models File "/home/ai/anaconda3/envs/reinforcement/lib/python3.5/site-packages/torchvision/models/init.py", line 11, in from . import detection File "/home/ai/anaconda3/envs/reinforcement/lib/python3.5/site-packages/torchvision/models/detection/init.py", line 1, in from .faster_rcnn import * File "/home/ai/anaconda3/envs/reinforcement/lib/python3.5/site-packages/torchvision/models/detection/faster_rcnn.py", line 7, in from torchvision.ops import misc as misc_nn_ops File "/home/ai/anaconda3/envs/reinforcement/lib/python3.5/site-packages/torchvision/ops/init.py", line 1, in from .boxes import nms, box_iou File "/home/ai/anaconda3/envs/reinforcement/lib/python3.5/site-packages/torchvision/ops/boxes.py", line 2, in from torchvision import _C ImportError: /home/ai/anaconda3/envs/reinforcement/lib/python3.5/site-packages/torchvision/_C.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _PyThreadState_UncheckedGet

2

2 Answers

1
votes

Problem solved: the problem was in Python 3.5, using Python 3.6 solves problem.

1
votes

Try this for anaconda:

conda install torchvision -c pytorch

Using pip:

pip install torchvision