Heroku Python Django App Deployment Failure: No module named 'oauth2_provider'

穿精又带淫゛_ 提交于 2021-02-10 15:56:19

问题


I am following the Django OAuth Toolkit tutorial. I have the app running successfully on my local server with Django OAuth Toolkit installed.

When I try to deploy to Heroku I get a "ModuleNotFoundError: No module named 'oauth2_provider'" error while running '$ python manage.py collectstatic --noinput'.

I have attempted to search Stack Overflow for similar questions but was unable to find one. I saw many questions on Stack Overflow relating to collectstatic but I do not think that is my problem.

My backtrace is as so:

remote: -----> Python app detected
remote: -----> Installing requirements with pip
remote: 
remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 10, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
remote:            django.setup()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
remote:            apps.populate(settings.INSTALLED_APPS)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
remote:            app_config = AppConfig.create(entry)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/config.py", line 94, in create
remote:            module = import_module(entry)
remote:          File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
remote:            return _bootstrap._gcd_import(name[level:], package, level)
remote:          File "<frozen importlib._bootstrap>", line 978, in _gcd_import
remote:          File "<frozen importlib._bootstrap>", line 961, in _find_and_load
remote:          File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
remote:        ModuleNotFoundError: No module named 'oauth2_provider'
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.

My settings.py Installed Apps is as so:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for
    # greater consistency between gunicorn and `./manage.py runserver`. See:
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'oauth2_provider',
    'corsheaders',
]

I am using Python 3.6.1 and my requirements.txt is as so:

dj-database-url==0.4.1
Django==1.11.1
gunicorn==19.6.0
psycopg2==2.6.2
whitenoise==3.2

回答1:


You're missing this package in your requirements.txt file. So add django-oauth-toolkit there and it should work




回答2:


Try installing the package "django-oauth-toolkit", execute:

pip install -U django-oauth-toolkit

or

pip3 install -U django-oauth-toolkit

Another fix could be upgrade your python version, I got this problem with python 2.7, but not with python 3.5



来源:https://stackoverflow.com/questions/44422226/heroku-python-django-app-deployment-failure-no-module-named-oauth2-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!