Skip to content

Instantly share code, notes, and snippets.

@tailhook
Created September 2, 2014 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tailhook/094378d50883457f2a31 to your computer and use it in GitHub Desktop.
Save tailhook/094378d50883457f2a31 to your computer and use it in GitHub Desktop.
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