简体   繁体   中英

Django error 'ModuleNotFoundError: No module named 'ocore'

New to Django and have just started building out a new project following a tutorial.

I have created a virtual environment as follows:

pip install virtualenv

virtualenv myproject_3_7_3

I then activate the virtual env and install Django as follows:

cd myproject_3_7_3

source bin/activate

pip install django

This installs Django version 3.2.10 successfully, so then I activate the project, add some folder structure and create an app using the following commands:

django-admin startproject myproject

cd myproject

mkdir apps

mkdir apps/core

python manage.py startapp core apps/core

I then open VSCode and I can see the project and all of the default folders/files there.

To start the app I run:

python manage.py startapp core apps/core

But I immediately get the following error in the terminal.

Traceback (most recent call last):
  File "/Users/myuser/myproject_3_7_3/lib/python3.7/site-packages/django/apps/config.py", line 244, in create
    app_module = import_module(app_name)
  File "//anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'ocore'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/myuser/myproject_3_7_3/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/Users/myuser/myproject_3_7_3/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    django.setup()
  File "/Users/myuser/myproject_3_7_3/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/myuser/myproject_3_7_3/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/Users/myuser/myproject_3_7_3/lib/python3.7/site-packages/django/apps/config.py", line 250, in create
    app_config_class.__qualname__,
django.core.exceptions.ImproperlyConfigured: Cannot import 'ocore'. Check that 'apps.core.apps.OcoreConfig.name' is correct.

Exploring the apps.py which gets created shows the following contents:

from django.apps import AppConfig


class OcoreConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'ocore'

This differs from the apps.py file given in the tutorial so my initial thought was that it might be due to a version difference, however searching this extensively yields no information about what ocore is or what this error means.

Is anyone able to help me resolve this issue?

Spelling mistake

I tried to replicate your error.

While creating the app you mistakenly created with name "ocore".

But in settings.py

INSTALLED_APPS = [
   ...
   apps.core, # This is what you added I presume
   apps.ocore, # this must be done
]

The created app name should be same in INSTALLED_APPS array present in settings.py of django.

One more thing "startapp" only just create the directory structure for you with required files and configuration. It will not run the project for that you have to do python manage.py runserver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM