I wrote these apps using python2 and now am using python 3.
I’ve tried:
1) Changing to a new virtualenv and reinstalling requirements
2) pip install config -> returns a new Syntax error in an Exception…
3) pip install django-config
4)
When running: python3 manage.py runserver
I keep getting the following error:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 308, in execute
settings.INSTALLED_APPS
File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'config'
I’m really stuck because i can’t run these project that i have worked on
I was getting the same error
ModuleNotFoundError: No module named 'chat_room'
Every time I create a new virtual environment and run python -m django
I got the same warning.
This warning is due to the fact that I set some environment variables for my old app which has the chat_room module
. so every time my new virtual environment uses my environment variable set in my .bash_profile instead of the default one in the new Django setting.
In the end, after getting rid of that environment variable export DJANGO_SETTINGS_MODULE=chat_room.settings
in my .bash_profile
everything went ok.
I received a similar error when copying or cloning my project directory.
ModuleNotFoundError: No module named ''
Creating a new venv wasn’t enough for me. I had to delete the old one first, not sure why.
Followed by these commands it worked like a charm after
pip install -r requirements.txt
python manage.py collectstatic
I did something similar to @PetarP:
INSTALLED_APPS = [
# user-defined
'blog.apps.BlogConfig',
# default
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# no 'django.contrib.sites'
]
as you can find this at /blog/apps.py
:
from django.apps import AppConfig
class BlogConfig(AppConfig):
name = 'blog'
After you create your module app with python manage.py startapp test_app
, you should go into settings.py
and register the app into
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
# Register your custom app here
'test_app',
]
You should read the official django tutorial everything will be explained there.