Skip to content

Commit 42e7f1f

Browse files
authored
Warn if torchvision imported from repo root (#2759)
* Warn if torchvision imported from repo root This is likely to fail as mentioned in #2239 * Only warn if ops are missing
1 parent 039c928 commit 42e7f1f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

torchvision/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import warnings
2+
import os
23

34
from .extension import _HAS_OPS
45

@@ -16,6 +17,14 @@
1617
except ImportError:
1718
pass
1819

20+
# Check if torchvision is being imported within the root folder
21+
if (not _HAS_OPS and os.path.dirname(os.path.realpath(__file__)) ==
22+
os.path.join(os.path.realpath(os.getcwd()), 'torchvision')):
23+
message = ('You are importing torchvision within its own root folder ({}). '
24+
'This is not expected to work and may give errors. Please exit the '
25+
'torchvision project source and relaunch your python interpreter.')
26+
warnings.warn(message.format(os.getcwd()))
27+
1928
_image_backend = 'PIL'
2029

2130
_video_backend = "pyav"

0 commit comments

Comments
 (0)