ImportError: No module named 'decouple' while deploying on Heroku
Asked Answered
G

7

11

I was trying to deploy my django project on heroku from heroku cli. So I created an app and then I ran git push heroku master from the project directory. Then I got the errors:

remote: -----> $ python manage.py collectstatic --noinput 
remote:      Traceback (most recent call last): 
remote:          File "manage.py", line 15, in <module> 
remote:            execute_from_command_line(sys.argv) 
remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line 
remote:            utility.execute() 
remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 317, in execute 
remote:            settings.INSTALLED_APPS 
remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__ 
remote:            self._setup(name) 
remote:   File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 43, in _setup remote:            self._wrapped = Settings(settings_module) 
remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 106, in __init__ 
remote:            mod = importlib.import_module(self.SETTINGS_MODULE) 
remote:          File "/app/.heroku/python/lib/python3.5/importlib/__init__.py", line 126, in import_module 
remote:            return _bootstrap._gcd_import(name[level:], package, level) 
remote:          File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
remote: File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
remote:          File "<frozen importlib._bootstrap>", line 958, in
_find_and_load_unlocked 
remote:          File "<frozen importlib._bootstrap>", line 673, in _load_unlocked 
remote:          File "<frozen importlib._bootstrap_external>", line 665, in exec_module 
remote:          File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 
remote:          File "/tmp/build_93c58c906371cd0110470b6bb3ccecc1/funderpreneur/settings.py", line 15, in <module> 
remote:            from decouple import Csv, config 
remote:        ImportError: No module named 'decouple' 
remote:  
remote:  !     Error while running '$ python manage.py collectstatic --noinput'. 
remote:        See traceback above for details. 
remote:  
remote:        You may need to update application code to resolve this error. 
remote:        Or, you can disable collectstatic for this application: remote:  
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1 
remote:  
remote:        https://devcenter.heroku.com/articles/django-assets 
remote:  !     Push rejected, failed to compile Python app. 
remote:  
remote:  !     Push failed

So as it is mentioned, I ran heroku config:set DISABLE_COLLECTSTATIC=1. Then the codes were pushed in the repository. Then I ran heroku run python3 manage.py migrate. But still I got the same error saying:

File "/app/funderpreneur/settings.py", line 15, in

from decouple import Csv, config ImportError: No module named 'decouple'

But I have python-decouple installed locally for both python 2 and 3. And also the whole project is running on django version 2 and python version 3.5.2. But in the runtime.txt I have set python-3.6.4. I have requirements.txt where decouple is already there.

In my settings.py I had

import django_heroku
django_heroku.settings(locals())

But I was getting errors so I commented them. Still getting error.

What is wrong or what am I doing wrong?

Edit

My requirements.txt:

dj-database-url
django
gunicorn
psycopg2
whitenoise
dj-static
Unipath
python-decouple
Pillow
Markdown
bleach
python-decouple
django-material
raven
django-debug-toolbar
django-tables2
django-phonenumber-field
django-guardian
django-notifications-hq
djangorestframework
matplotlib
numpy
seaborn
pandas
django-heroku

And the strucutre is:

.
├── core
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── __init__.py
│   │   └── __pycache__
│   │       └── __init__.cpython-35.pyc
│   ├── models.py
│   ├── __pycache__
│   │   ├── admin.cpython-35.pyc
│   │   ├── __init__.cpython-35.pyc
│   │   ├── models.cpython-35.pyc
│   │   └── views.cpython-35.pyc
│   ├── templates
│   │   └── core
│   │       ├── base.html
│   │       ├── footer.html
│   │       ├── index.html
│   │       ├── login.html
│   │       ├── navbar.html
│   │       ├── nav.html
│   │       ├── partial_settings_menu.html
│   │       ├── password.html
│   │       ├── picture.html
│   │       ├── profile.html
│   │       └── registration.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── db.sqlite3
├── funderpreneur
│   ├── fonts
│   │   ├── material-design-icons
│   │   │   ├── Material-Design-Iconsd41d.eot
│   │   │   ├── Material-Design-Icons.svg
│   │   │   ├── Material-Design-Icons.ttf
│   │   │   └── Material-Design-Icons.woff
│   │   └── roboto
│   │       ├── Roboto-Bold.ttf
│   │       ├── Roboto-Bold.woff
│   │       ├── Roboto-Light.ttf
│   │       ├── Roboto-Light.woff
│   │       ├── Roboto-Medium.ttf
│   │       ├── Roboto-Medium.woff
│   │       ├── Roboto-Regular.ttf
│   │       ├── Roboto-Regular.woff
│   │       ├── Roboto-Thin.ttf
│   │       └── Roboto-Thin.woff
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-35.pyc
│   │   ├── settings.cpython-35.pyc
│   │   ├── urls.cpython-35.pyc
│   │   └── wsgi.cpython-35.pyc
│   ├── settings.py
│   ├── static
│   │   ├── css
│   │   │   ├── account-settings.css
│   │   │   ├── bootstrap.min.css
│   │   │   ├── custom-materialize.css
│   │   │   ├── footer.css
│   │   │   ├── high-rise-building.jpg
│   │   │   ├── materialize.css
│   │   │   ├── navbar.css
│   │   │   ├── navbar-top-fixed.css
│   │   │   ├── style2.css
│   │   │   └── style.css
│   │   ├── humans.txt
│   │   ├── img
│   │   │   └── buet_logo.png
│   │   └── js
│   │       ├── bootstrap.min.js
│   │       ├── circular-progress-jquery.js
│   │       ├── jquery-1.11.2.min.js
│   │       ├── jquery-slim.min.js
│   │       ├── jquery.waypoints.min.js
│   │       ├── materialize.js
│   │       ├── popper.min.js
│   │       ├── profile-validation.js
│   │       └── registration-validation.js
│   ├── urls.py
│   └── wsgi.py
├── manage.py
├── media
├── Pipfile
├── Procfile
├── README.md
├── requirements.txt
├── runtime.txt
└── staticfiles
Greylag answered 28/3, 2018 at 18:6 Comment(2)
Please show the actual requirements.txt, and the layout of your project.Stansbury
I have edited my question.Greylag
G
3

I think you haven't written packages name from requirements.txt to the Pipfile bellow [packages] section. You should add packages in this format-

package_name = "version"
Guardhouse answered 31/3, 2018 at 16:9 Comment(1)
I'm having the same issue as OP, can you please expand on this answer? Should be [packages] section contain all packages from requirements.txt? I tried including python-decouple = "==3.1" within [packages] to no avail. Currently, my [packages] contains only django = "==2.1.2".Febrifugal
F
9

I also had this problem, but by adding

python-decouple==3.1

into the requirements.txt file, I was able to get past it!

Folks answered 18/12, 2018 at 22:17 Comment(0)
H
8

You need to install the decouple module on your device. An event independent of the version change

try:

pip install python-decouple

no requirements.txt file

Homozygous answered 7/5, 2021 at 13:3 Comment(0)
G
3

I think you haven't written packages name from requirements.txt to the Pipfile bellow [packages] section. You should add packages in this format-

package_name = "version"
Guardhouse answered 31/3, 2018 at 16:9 Comment(1)
I'm having the same issue as OP, can you please expand on this answer? Should be [packages] section contain all packages from requirements.txt? I tried including python-decouple = "==3.1" within [packages] to no avail. Currently, my [packages] contains only django = "==2.1.2".Febrifugal
S
2

I had the same problem, I'm new to django. The steps above didn't work after updating requirements.txt until I switched env.

source env/Scripts/activate
pip install -r requirements.txt
py manage.py runserver
Seicento answered 31/7, 2020 at 11:32 Comment(0)
V
1

I also had this problem and solved by removing all package (removed 2x python-decouple from locally and decouple) from my env and locally. Then, I installed python-decouple (3.3) again.

Vying answered 19/6, 2020 at 11:43 Comment(0)
C
1

I had an error similar to this, turns out you have to install the module in the virtual environment. First, launch the virtual environment, then install the module(inside the virtual environment). Now try to launch your server, the problem should be solved In some cases, there might be a module "decouple' installed, uninstall that module before launching your server as it will cause an error

Critical answered 27/4, 2021 at 22:2 Comment(0)
I
1

I had this issue because i had mistakenly pip install decouple instead of pip install python-decouple.

So just pip uninstall decouple , and make sure the decouple package has been removed from either your requirements.txt or your Pipfile/Pipfile.lock files.

Then run pip install python-decouple

Immunogenic answered 20/8, 2022 at 9:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.