Heroku Python Django应用程序部署失败:没有名为'oauth2_provider'的模块

问题描述 投票:1回答:2

我跟随Django OAuth Toolkit tutorial。我已经在安装了Django OAuth Toolkit的本地服务器上成功运行了应用程序。

当我尝试部署到Heroku时,我在运行'$ python manage.py collectstatic --noinput'时遇到“ModuleNotFoundError:没有名为'oauth2_provider'的模块”错误。

我试图搜索Stack Overflow的类似问题,但无法找到。我在Stack Overflow上看到了很多关于collectstatic的问题,但我认为这不是我的问题。

我的回溯是这样的:

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.

我的settings.py已安装的应用程序如下:

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',
]

我正在使用Python 3.6.1,我的requirements.txt如下:

dj-database-url==0.4.1
Django==1.11.1
gunicorn==19.6.0
psycopg2==2.6.2
whitenoise==3.2
python django heroku oauth-2.0
2个回答
4
投票

你在requirements.txt文件中遗漏了这个包。所以在那里添加django-oauth-toolkit它应该工作


0
投票

尝试安装包“django-oauth-toolkit”,执行:

pip install -U django-oauth-toolkit

要么

pip3 install -U django-oauth-toolkit

另一个修复可能是升级你的python版本,我遇到python 2.7的问题,但不是python 3.5

© www.soinside.com 2019 - 2024. All rights reserved.