user9885031
user9885031

Reputation:

ImportError of a submodule of a module, when running another different module

I have a structure as

name_folder:
    tobeused.py
    name_folder:
          __init__.py
          models.py
          radial.py

In module tobeused.py I did from name_folder import models.

In module models.py I did from radial import rad (rad is function in radial.py)

When I run models.py directly, it works. But when I run tobeused.py an error shows :

ImportError: No module named 'radial'

How to work on this? Thanks

Upvotes: 2

Views: 60

Answers (2)

madjaoue
madjaoue

Reputation: 5224

add __init__.py file to your folder

tobeused.py
folder:
      __init__.py
      models.py
      radial.py

Detailed explanation : What is __init__.py for?

The import :

from folder.models import something

Upvotes: 1

Magnetron
Magnetron

Reputation: 377

Change from radial import rad to from .radial import rad

The . allows the file to look locally rather than within the working directory.

Upvotes: 1

Related Questions