ImportError: No module named 'decouple' while deploying on Heroku
ImportError: No module named 'decouple' while deploying on Heroku
我试图通过 heroku cli 在 heroku 上部署我的 django 项目。所以我创建了一个应用程序,然后我从项目目录 运行 git push heroku master
。然后我得到了错误:
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
所以正如提到的那样,我运行 heroku config:set DISABLE_COLLECTSTATIC=1
。
然后代码被推送到存储库中。那我运行heroku run python3 manage.py migrate
。但我仍然遇到同样的错误:
File "/app/funderpreneur/settings.py", line 15, in
from decouple import Csv, config ImportError: No module named 'decouple'
但是我在本地为 python 2 和 3 安装了 python-decouple。而且整个项目都在 运行 django 版本 2 和 python 版本 3.5.2。但是在runtime.txt
中我设置了python-3.6.4
。我有 requirements.txt
,其中 decouple
已经存在。
在我的 settings.py
我有
import django_heroku
django_heroku.settings(locals())
但是我遇到了错误,所以我对它们进行了评论。仍然出现错误。
哪里出了问题或者我做错了什么?
编辑
我的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
结构是:
.
├── 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
我认为您还没有将 requirements.txt
中的软件包名称写到 [packages]
部分下面的 Pipfile
中。您应该以这种格式添加包-
package_name = "version"
我也遇到了这个问题,但是通过添加
python-decouple==3.1
进入requirements.txt
文件,我成功通过了!
我也有这个问题,通过从我的环境和本地删除所有包(从本地删除 2x python-decouple 和 decouple)解决了这个问题。然后,我又安装了python-decouple(3.3)。
我遇到了同样的问题,我是 django 的新手。更新 requirements.txt
后上述步骤无效,直到我切换 env
.
source env/Scripts/activate
pip install -r requirements.txt
py manage.py runserver
我有一个类似的错误,原来你必须在虚拟环境中安装模块。首先,启动虚拟环境,然后安装模块(在虚拟环境中)。现在尝试启动你的服务器,问题应该解决了
在某些情况下,可能安装了“解耦”模块,在启动服务器之前卸载该模块,因为它会导致错误
python python-decouple django
您需要在您的设备上安装解耦模块。独立于版本更改的事件
尝试:
pip install python-decouple
没有requirements.txt文件
我试图通过 heroku cli 在 heroku 上部署我的 django 项目。所以我创建了一个应用程序,然后我从项目目录 运行 git push heroku master
。然后我得到了错误:
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
所以正如提到的那样,我运行 heroku config:set DISABLE_COLLECTSTATIC=1
。
然后代码被推送到存储库中。那我运行heroku run python3 manage.py migrate
。但我仍然遇到同样的错误:
File "/app/funderpreneur/settings.py", line 15, in
from decouple import Csv, config ImportError: No module named 'decouple'
但是我在本地为 python 2 和 3 安装了 python-decouple。而且整个项目都在 运行 django 版本 2 和 python 版本 3.5.2。但是在runtime.txt
中我设置了python-3.6.4
。我有 requirements.txt
,其中 decouple
已经存在。
在我的 settings.py
我有
import django_heroku
django_heroku.settings(locals())
但是我遇到了错误,所以我对它们进行了评论。仍然出现错误。
哪里出了问题或者我做错了什么?
编辑
我的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
结构是:
.
├── 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
我认为您还没有将 requirements.txt
中的软件包名称写到 [packages]
部分下面的 Pipfile
中。您应该以这种格式添加包-
package_name = "version"
我也遇到了这个问题,但是通过添加
python-decouple==3.1
进入requirements.txt
文件,我成功通过了!
我也有这个问题,通过从我的环境和本地删除所有包(从本地删除 2x python-decouple 和 decouple)解决了这个问题。然后,我又安装了python-decouple(3.3)。
我遇到了同样的问题,我是 django 的新手。更新 requirements.txt
后上述步骤无效,直到我切换 env
.
source env/Scripts/activate
pip install -r requirements.txt
py manage.py runserver
我有一个类似的错误,原来你必须在虚拟环境中安装模块。首先,启动虚拟环境,然后安装模块(在虚拟环境中)。现在尝试启动你的服务器,问题应该解决了 在某些情况下,可能安装了“解耦”模块,在启动服务器之前卸载该模块,因为它会导致错误 python python-decouple django
您需要在您的设备上安装解耦模块。独立于版本更改的事件
尝试:
pip install python-decouple
没有requirements.txt文件