New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unexpected system error with pep420 style namespace packages #68380
Comments
The script below creates a basic PEP-420 style package with a single module in it ('package.sub') and tries to import that module With 3.5 the script runs without problems and prints 42 (as expected). With a 3.5 (fresh checkout as of 2015-05-14) I get an SystemError: $ python3.5 demo.py
Traceback (most recent call last):
File "demo.py", line 10, in <module>
import package.mod
File "<frozen importlib._bootstrap>", line 958, in _find_and_load
File "<frozen importlib._bootstrap>", line 947, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
File "<frozen importlib._bootstrap>", line 575, in module_from_spec
File "<frozen importlib._bootstrap>", line 519, in _init_module_attrs
SystemError: Parent module '' not loaded, cannot perform relative import #######
import os
os.mkdir('path1')
os.mkdir('path1/package')
with open('path1/package/mod.py', 'w') as fp:
fp.write('print(42)\n')
import site
site.addsitedir('path1')
import package.mod |
I presume you meant that it works with 3.4? |
The problem is right where the traceback says. Apparently there is a gap in the namespace package tests that I slipped through with my recent work to split out path-based import. I'll work up a patch. |
Hmm, look like the test suite masks the issue due to the fact that importlib gets imported before running the applicable tests in test_namespace_pkgs.py. This causes _frozen_importlib.__package__ to get set properly, thus masking the problem. The problem is the use of relative imports in importlib._bootstrap. The solution is to accomplish this in a different way. |
Here's a fix. If I don't hear from anyone right away I'll push it in a few hours (or tomorrow morning). |
New changeset 46b2c99121f5 by Eric Snow in branch 'default': |
I can confirm that this fixes the problem I was having, both for the sample code I posted and for the real codebase I extracted this from. Thanks. |
Great! The buildbots are happy too. :) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: