Search code examples
djangopython-3.xamazon-s3boto3boto

Could not load Boto3's S3 bindings


I'm deploying to Heroku a Django==2.1.2 and Python==3.6.5 app and i would to manage media and static files with Amazon S3.

Here's my settings.py:

INSTALLED_APPS = (
    ...
    'storages',
)

AWS_STORAGE_BUCKET_NAME = '****'
AWS_ACCESS_KEY_ID = '***'
AWS_SECRET_ACCESS_KEY = '***'
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' %  AWS_STORAGE_BUCKET_NAME

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'custom_files_storage.StaticFilesStorage'

MEDIAFILES_LOCATION = 'media'
MEDIAFILES_STORAGE = 'custom_files_storage.MediaFilesStorage'

Here's my custom_files_storage.py:

from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage

class MediaFilesStorage(S3Boto3Storage):
    location = settings.MEDIAFILES_LOCATION

class StaticFilesStorage(S3BotoStorage):
    location = settings.STATICFILES_LOCATION

I have runed:

pip install boto

pip install boto3

pip install django-storges

I have tried with boto and boto3 but the error keeps

Here's the error output:

File "/app/.heroku/python/lib/python3.6/site-packages/storages/backends/s3boto3.py" in <module>
  32.     raise ImproperlyConfigured("Could not load Boto3's S3 bindings.\n"

Exception Type: ImproperlyConfigured at /registro/
Exception Value: Could not load Boto3's S3 bindings.
See https://github.com/boto/boto3

I don't know how to fix it Someone could help me please? Thanks in advance.


Solution

  • I had the same issue. I solved it by adding 'boto3' package and version to pipfile (run pipenv lock) and then push to Heroku.