votes up 2

attempted relative import with no known parent package

github stars 50580
Exception Class:

Raise code

e TypeError("module name must be str, not {}".format(type(name)))
    if level < 0:
        raise ValueError("level must be >= 0")
    if level > 0:
        if not isinstance(package, str):
            raise TypeError("__package__ not set to a string")
        elif not package:
            raise ImportError(
                "attempted relative import with no known parent " "package"
    if not name and level == 0:
        raise ValueError("Empty module name")

def _calc___package__(globals):
    """Calcu """
😲 Agile task management is now easier than calling a taxi. #Tracklify
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 1 votes down

This is very easy way to fix this problem is -

Step 1 : creating setup file -

from setuptools import setup, find_packages

setup(name = 'package_name', packages = find_packages())

step 2: Run this - python install

It will create package into site_packages and make your custom package global.

Get complete detail here

Feb 28, 2022 scien.abhishek answer
votes up 1 votes down

The exception is thrown when importing a module with relative import(start with a dot).

Relative import is used to import a package from the same level where you are.

├ mylib/
│ ├
│ └

For example, you have file structures like this.

inside, you could have from . import module2, because here the . stands for mylib.

Each file (folder) has its parent. So relative import helps us to call parents of files easily. But when we trying to call a parent model which it doesn't have a parent, we will get an error.

Error code:

from .torch import nn

We can't use the above code, because the torch itself is a top-level parent, it doesn't have a parent package.

Fix version:

from torch import nn

 You can check here to get more information about error.

Oct 05, 2021 anonim answer
anonim 13.0k

Add a possible fix

Please authorize to post fix