![](/img/trans.png)
[英]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.