[英]Importing installed package from script with the same name raises "AttributeError: module has no attribute" or "ImportError: cannot import name"
[英]Python AttributeError/ImportError when importing from same folder
我的代码:
from fin.py import *
from setup.py import *
我的错误:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1519, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\name\Documents\Programming\snake.py", line 4, in <module>
from fin.py import *
ImportError: No module named 'fin.py'; fin is not a package
我正在从同一文件夹导入.py文件。 一切都应该正常,但这显示出来了!
编辑:解决了! (从末尾删除.py,我之前曾尝试过此操作,但由于我的代码中有错字,出现了NameError。所以是!太棒了!
导入时,您可以在文件末尾省略.py。 您正在寻找的是:
from fin import *
from setup import *
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.