简体   繁体   中英

attempted relative import with no known parent package in anaconda(python 3.8.5) with vscode

Image of the error i am using anaconda(python 3.8.5) in vscode i am importing the y.py to the x.py by saying # note: both my x and y are on the same folder named blog

the statement i used for importing is

from.x import func_name

but i am having issues with the relative import saying that: ERROR:Exception has occurred: ImportError attempted relative import with no known parent package File "C:\Users\rbw19\bharathwajan\blog\x.py", line 2, in from.models import data

In VSCode, when importing other files, VSCode searches for the imported file ("models.py") from the parent folder of the currently opened file ("views.py") by default, so we can use " from models import data ":

在此处输入图像描述

The Python language service I use is Jedi .

"python.languageServer": "Jedi",

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM