ModuleNotfoundError <projectname>.users in cookiecutter django project

Hi all,

I have an app I am moving to production on Linode. It is named hr_py

This is my first time using a PaaS and having to install all the applications. Prev I have used pythonanywhere. It’s been a learning experience!

Locally the app works fine. It is running Python 3.7 on Windows

The Production is Ubuntu 20something with Python 3.8

Prod is running in a virtual environment.

The Django app base is django-cookiecutter by @pydanny (Thanks Daniel!)

When I begin the first migrate

python3 manange.py migrate

I get the following error:

ModuleNotFoundError: No module named 'hr_py.users'

Full error:

The settings file (base.py) has this code:

LOCAL_APPS = [
     'hr_py.users.apps.UsersAppConfig',
     # Your stuff: custom apps go here
    .....
]

The file hr_py/users/apps is:

from django.apps import AppConfig

class UsersAppConfig(AppConfig):
    name = "hr_py.users"
    verbose_name = "Users"

    def ready(self):
        try:
            import users.signals  # noqa F401
        except ImportError:
            pass

There seems to be nothing out of place and the file exists so why is it erroring out?

I’ve done a lot of googling and I couldn’t find this error.

Any ideas from you fine folks?

Thanks!

Deploying to a PaaS is certainly a challenge. I haven’t finished it yet but I’ve been working through this tutorial by Corey Schafer on deploying to Linode, maybe it could be useful for you too. I’ve also heard (on Hacker Public Radio) the book SSH Mastery recommended for learning about how ssh works, but I’ve only read a couple of chapters in it. So far it’s good though.

Could you describe the directory/tree structure of your project? I don’t recognize the pattern you are describing. If your app itself is hr_py, as you describe, then usually one would expect the apps file to be in the hr_py directory itself. Now it seems like you have “an app inside of an app”, i. e. a users app put inside of the hr_py app, which seems odd.

1 Like

Yes Cookiecutter puts the users app inside of the project app. I’m not sure why but I suspect they have thought deeply about it.

The directory structure is hr_py, with all the apps on the same level as that. (The project is for horse management, so there are apps like horses, events, people etc.)

-> hr
    -> users
-> horses
-> people
-> events

The users app is a child to hr_py which is how Cookiecutter set it up firstly.

The weird thing is the project works fine locally - but in production it doesnt, which makes me think there is something not right in production.

I worked it out!

There was a stray init and a urls.py in the root dir for some reason.

This was stuffing up the pathing.

A simple fix in the end!

1 Like