close

[Solved] ImportError: attempted relative import with no known parent package :(

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error ImportError: attempted relative import with no known parent package 🙁 in Python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How ImportError: attempted relative import with no known parent package 🙁 Error Occurs?

Today I get the following error ImportError: attempted relative import with no known parent package 🙁 in Python.

How To Solve ImportError: attempted relative import with no known parent package 🙁 Error ?

  1. How To Solve ImportError: attempted relative import with no known parent package 🙁 Error ?

    To Solve ImportError: attempted relative import with no known parent package 🙁 Error
    Remove the dot from the beginning. Relative paths with respect to main.py are found automatically. from Items.Quest1_items import *

Solution 1

Remove the dot from the beginning. Relative paths with respect to main.py are found automatically.

from Items.Quest1_items import *

Solution 2

You can only perform relative import (ie., starting with a dot), inside a package that you import. For instance, imagine the situation:

project/
├ main.py
├ mylib/
├ __init__.py
│ ├ module1.py
│ └ module2.py

in main.py, you would have import mylib or from mylib import *, but inside module1.py, you could have from . import module2, because here the . stands for mylib (which is a python package, because you imported it within main.py).

So, the solution is simply remove the dot, it’s not useful in your situation.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment