diff --git a/torchvision/__init__.py b/torchvision/__init__.py index 52a4ef1a09d..28349cbb78a 100644 --- a/torchvision/__init__.py +++ b/torchvision/__init__.py @@ -1,4 +1,5 @@ import warnings +import os from .extension import _HAS_OPS @@ -16,6 +17,14 @@ except ImportError: pass +# Check if torchvision is being imported within the root folder +if (not _HAS_OPS and os.path.dirname(os.path.realpath(__file__)) == + os.path.join(os.path.realpath(os.getcwd()), 'torchvision')): + message = ('You are importing torchvision within its own root folder ({}). ' + 'This is not expected to work and may give errors. Please exit the ' + 'torchvision project source and relaunch your python interpreter.') + warnings.warn(message.format(os.getcwd())) + _image_backend = 'PIL' _video_backend = "pyav"