Created
September 2, 2014 15:15
-
-
Save tailhook/094378d50883457f2a31 to your computer and use it in GitHub Desktop.
Python Import Error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from . import first | |
from . import hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print('first') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
if os.environ.get('BROKEN'): | |
raise RuntimeError("Broken module") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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