Skip to content
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

TypeError: '_NamespacePath' object does not support indexing #5

Closed
ZhaoQi99 opened this issue Nov 18, 2021 · 2 comments
Closed

TypeError: '_NamespacePath' object does not support indexing #5

ZhaoQi99 opened this issue Nov 18, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@ZhaoQi99
Copy link
Owner

报错如下

Traceback (most recent call last):
  File "a.py", line 3, in <module>
    from test.test2.abc import *
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 894, in _find_spec
  File "/Users/zhaoqi219/Code/python_encrypt/encrypted/loader.py", line 411, in find_spec
    file_path = Path(path[0]) / f'{fullname.rsplit(".",1)[-1]}.pye'
TypeError: '_NamespacePath' object does not support indexing

目录结构是

test
├── __init__.py
└── test2
    └── abc.py

代码是

import loader
from test.test2.abc import *
@ZhaoQi99 ZhaoQi99 added the bug Something isn't working label Nov 18, 2021
@ZhaoQi99
Copy link
Owner Author

test2目录下不存在__init__.py文件时,传给find_spec函数的实参path是个_NamespacePath对象,而不是list

@ZhaoQi99
Copy link
Owner Author

test2目录下不存在__init__.py文件时,传给find_spec函数的实参path是个_NamespacePath对象,而不是list

可通过test2目录下添加__init__.py文件解决问题

@ZhaoQi99 ZhaoQi99 reopened this Nov 18, 2021
@ZhaoQi99 ZhaoQi99 reopened this Nov 18, 2021
ZhaoQi99 added a commit that referenced this issue Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant