Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python Import Error
from . import first
from . import hello
import os
if os.environ.get('BROKEN'):
raise RuntimeError("Broken module")
> python2 test.py
first
ok
> BROKEN=1 python2 test.py
first
('Err', "RuntimeError('Broken module',)")
Traceback (most recent call last):
File "test.py", line 8, in <module>
import pkg.hello
File "/home/pc/tmp/testpy/pkg/__init__.py", line 1, in <module>
from . import first
ImportError: cannot import name first
try:
import pkg.hello
except Exception as e:
print("Err", repr(e))
else:
print('ok')
import pkg.hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment