Alexmhack/Django-Rasa-Bot

ModuleNotFoundError: No module named 'decouple'

satishAarbor opened this issue · 3 comments

when i"m try run the command "python manage.py runserver" following error occurs

Traceback (most recent call last):
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 60, in execute
super().execute(*args, **options)
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 67, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/conf/init.py", line 57, in getattr
self._setup(name)
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/conf/init.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/conf/init.py", line 107, in init
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/aarbor_01/anaconda3/lib/python3.6/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "/home/aarbor_01/Desktop/django-Rasa-Bot/chatsite/settings.py", line 15, in
from decouple import config
ModuleNotFoundError: No module named 'decouple'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "manage.py", line 15, in
execute_from_command_line(sys.argv)
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/core/management/init.py", line 381, in execute_from_command_line
utility.execute()
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/core/management/init.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 329, in run_from_argv
connections.close_all()
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/db/utils.py", line 220, in close_all
for alias in self:
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/db/utils.py", line 214, in iter
return iter(self.databases)
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/utils/functional.py", line 37, in get
res = instance.dict[self.name] = self.func(instance)
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/db/utils.py", line 147, in databases
self._databases = settings.DATABASES
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/conf/init.py", line 57, in getattr
self._setup(name)
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/conf/init.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/aarbor_01/anaconda3/lib/python3.6/site-packages/django/conf/init.py", line 107, in init
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/aarbor_01/anaconda3/lib/python3.6/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "/home/aarbor_01/Desktop/django-Rasa-Bot/chatsite/settings.py", line 15, in
from decouple import config
ModuleNotFoundError: No module named 'decouple'

Yeah It's my fault. The error occurred because I use python-decouple for fetching the environment variables from the .env file which is ignored in the git repository. Python Decouple is very useful tool for hiding the SECRET_KEY of Django which is very recommended when your deploy Django to production.

Solution:
The simplest solution for your issue is to edit the chatsite/settings.py file and clear out the import statement for python-decouple by removing from decouple import config and also using any random value for SECRET_KEY by changing SECRET_KEY = config("PROJECT_KEY") to SECRET_KEY = 'abc'.

Make the following changes in chatsite/settings.py file and run the Django server again by python manage.py runserver.

If you want to know about the use of python-decouple then just reply me.

thanks it was works fine.

Hey Alex,

I have cloned one project not yours but other from github and had this same error:
from .base import *
File "H:\study material\Web development\React\ecom\django-ecommerce\djecommerce\settings\base.py", line 2, in
from decouple import config
ModuleNotFoundError: No module named 'decouple'

I tried solution the way you mentioned above like this :
import os

BASE_DIR = os.path.dirname(os.path.dirname(
os.path.dirname(os.path.abspath(file))))
SECRET_KEY = 'abc'

but it's not helping me