Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Import Error: No module named apps

I just checked out a project with git. The project structure is

project
  apps
    myapp
      settings
        __init__.py
      __init__.py
    manage.py

There are other directories and files, but I think those are the important ones.

When I run the server I get

    Traceback (most recent call last):
  File "C:/Dev/project/apps/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 345, in execute
    settings.INSTALLED_APPS
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 46, in __getattr__
    self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 98, in __init__
    % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'apps.myapp.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named apps.myapp.settings

When running manage.py check I get ImportError: No module named apps. so I guess the problem has nothing to do with my setting module but with my apps directory. I'm not sure why it can't find my module apps, because project is on my sys.path and the direcory apps obviously exists. As I'm not very experienced as a Python developer I don't find a solution myself.

like image 335
Josh Avatar asked May 02 '15 10:05

Josh


People also ask

How do I fix Django error module not found?

To solve the error, install the module by running the pip install Django command. Open your terminal in your project's root directory and install the Django module. Copied! After you install the Django package, you should be able to import it and use it.


2 Answers

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.

Have a look at the documentation for more informations.

like image 160
aumo Avatar answered Sep 22 '22 17:09

aumo


If you've used the django-admin startapp myapp command, it creates this file: myapp/apps.py.

It could be conflicting with your apps/ module folder. A hidden apps.pyc file could be in your myapp/ folder.

Try removing these:

  • project/apps/myapp/apps.py
  • project/apps/myapp/apps.pyc
like image 21
Ruben Avatar answered Sep 20 '22 17:09

Ruben