bballboy8
bballboy8

Reputation: 450

ModuleNotFoundError: No module named 'apps.news'; 'apps' is not a package

I have a Django project with the following structure:

project
   apps
      news
      __init__.py
         models.py
   hose
      tasks.py

Within tasks.py, I have this import

from apps.news.models import Company

When I try to run tasks.py, I get the following error:

ModuleNotFoundError: No module named 'apps.news'; 'apps' is not a package

How do I fix this error? I don't understand why this import does not work.

Upvotes: 2

Views: 8766

Answers (2)

omufeed
omufeed

Reputation: 162

In case anybody else is still struggling with this. I had the __init__.py in the app folder but it still didn't work. Running the following command in app parent folder worked for me.

export PYTHONPATH=$PWD

Upvotes: 0

Shamsheer
Shamsheer

Reputation: 744

Reference: https://docs.python.org/2/tutorial/modules.html#packages

You need to add an empty __init__.py (4 underscores in total) file in the apps folder for it to be recognized by Python as a package.

Upvotes: 1

Related Questions