Django storages: Import Error - no module named storages - django

I'm trying to use Django's storages backend (for BotoS3)
settings.py:
INSTALLED_APPS = (
...
'storages',
...
)
as shown in http://django-storages.readthedocs.org/en/latest/index.html.
and, requirements.txt:
django-storages==1.1.8
But am getting the error:
django.core.exceptions.ImproperlyConfigured: ImportError storages: No module named storages
What am I doing wrong?

There is a possibility that you are in a virtualenv and installing the package outside the virtualenv into the default python installation. Make sure you are not doing that.

If you are experiencing this error even though you've included 'storages' in your INSTALLLED_APPS and django-storages in your requirements.txt, check your STATICFILES_STORAGE variable.
For previous versions of django-storages, this should be set as:
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
For newer versions of django-storages, the package uses boto3 instead of boto and this variable should be set as:
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
If you're using either version and you've configured your DEFAULT_FILE_STORAGE setting incorrectly, you'll receive an import error.
The correct settings can be found in the django-storages docs

I had the same problem.
In my case I solved the problem with
pip install django-storages
Collecting django-storages
Downloading django_storages-1.6.5-py2.py3-none-any.whl (47kB)
100% |################################| 51kB 358kB/s
Installing collected packages: django-storages
Successfully installed django-storages-1.6.5
It was executed inside my virtual environment.

I had installed it within virtual env and was running the exact same issue. My problem was that I forgot to update my requirements.txt. So make you update that file!

If you are using Pipenv make sure you install django-storages using
pipenv install django-storages
so that the Pipfile and Pipfile.lock are both updated.
I had installed using pip inside the virtualenv and requirements.txt was updated but still receiving this error. After digging around I noticed it was not added to the Pipfile. I ran the installer and it cleared up the error.

I installed with:
pip install -U django-storages
If you go to venv/lib/python3.8/site-packages/storages/backends you will see no file named S3Boto but S3Boto3. I dropped in an old S3Boto file from an old virtual environment and everything worked again.

I was using virtual environment and installed django-storage as well as boto3 . But still I was getting these errors.
Initially I installed the packages using this command
pip install django-storages, boto3
This command solved my Issue
pip install -U django-storages
pip install -U boto3
It updates the packages

EDX only if you are in local then run this command
paver update_assets --theme-dirs=/edx/app/edxapp/edx-platform/themes/theme-name/

Related

No module named PIL in heroku though it is installed

I have been trying to deploy a Django application on Heroku.
Some background - I hadn't used virtual environment while building the application but while deploying it, I had to use it. I'm following this tutorial for deployment. https://medium.com/agatha-codes/9-straightforward-steps-for-deploying-your-django-app-with-heroku-82b952652fb4
Now I'm stuck in step-6. After creating a virtual environment I have freezed the dependencies into requirements.txt.
But when I open the deployed URL it says
ImportError at /
No module named PIL
though Pillow has been installed, it is there in requirements.txt and runs fine when hosted on a local server.
This is my requirements.txt.
certifi==2018.4.16
dj-database-url==0.5.0
Django==1.11.14
django-heroku==0.3.1
gunicorn==19.9.0
packaging==17.1
Pillow==5.2.0
pip-review==1.0
pipenv==2018.7.1
pkg-resources==0.0.0
psycopg2==2.7.5
pyparsing==2.2.0
pytz==2018.5
six==1.11.0
virtualenv==16.0.0
virtualenv-clone==0.3.0
whitenoise==3.3.1
Please help me with this.
Heroku? Access your application and manually run pip install -r requirements.txt, then turn the application off and back on again.
I had this problem before, this step solved my problem.
If you are doing this in your view
import PIL
do this
import Image
In my case I solved this issue by installing 'Pillow'... just try pip/pip3 install Pillow and add it to your requirements.txt file.

Can't find any modules in Django project

I've been following a Django tutorial and initially created virtualenv and a requirements file in it. Project was halfway and in working state. Today I activated virtualenv successfully and tried python manage.py runserver to get error
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
I realized it's not finding Django and just to be sure checked my requirements.txt file (which confirmed right Django version). Tried to reinstall it from the file using pip3 install -r requirements.txt (tried using just pip too) to get another error --
ModuleNotFoundError: No module named 'pip'
It seems the environment is unable to find any of the modules. I tried to reinstall pip also just to be sure, but then it couldn't find apt-get command.
OS: Mac OSX El Capitan 10.11.6
Python: 3.6.2
Django: 1.10.3 (in requirements file)
Try running python -m ensurepip (or python3 -m ensurepip) to see if pip is already installed:
In most cases, end users of Python shouldn’t need to invoke this module directly (as pip should be bootstrapped by default), but it may be needed if installing pip was skipped when installing Python (or when creating a virtual environment) or after explicitly uninstalling pip.

deploying to heroku from local machine

I have django project running on my machine in virtualenv. Is there a way I can deploy my project on Heroku directly? I followed steps mentioned in heroku documentation but i am kind of confused with req.txt since my project already have req.txt in virtualenv. I am new to django heroku techs. Any guidance is highly appreciated.
my project already have req.txt in virtualenv
You should not have req.txt in virtualenv. You should have requirements.txt in your project repository. requirements.txt is just a list of modules that need to be installed in the virtualenv. You create and activate a new virtualenv, then you run pip install -r requirements.txt, and it installs everything you need in the virtualenv. So requirements.txt is not part of the virtualenv, it's more like a description of how to setup the virtualenv.
If this is not clear, you may find my article, virtualenv demystified, useful.
The requirements.txt file defines what python dependencies Heroku will install. Generally speaking, what you use locally will be the same as your local development machine.
If there are differences, you may opt to have an additional file locally that contains local, development-specific packages (for example django-debug-toolbar).
First you will activate your virtual environment and then go to project root and run the command
pip freeze > requirements.txt
This will automatically add all the dependencies of your local machine in requirements.txt. Once you push the file heroku will automatically detect the changes and install them.

Path issue Pip (Psycopg2) inside VirtualEnv

When using Pip (6.0.8) to install Django (1.9) and Psycopg2 (2.6.1), Django got installed in the env/lib/python2.7/site-packages folder and Psycopg2 in the env/lib64/python2.7/site-packages folder.
When I'm using command line (eg python manage.py migrate) or >>> import psycopg2, this all works fine. But when Mod_WSGI is running the application it complains that there is no module Psycopg2.
I'm able to work around this issue by adding the lib64 as a python path in my Apache conf file, but I'm pretty sure this is not the best possible way.
Any suggestions for a better solution?
Btw: I noticed by the way that Pip 7.1.2 is installing Django in Lib64 as well iso Lib.
Yes, there is with the use of --install-option. Have a look at the docs

Django Twilio module is not getting installed on Heroku

I tried below 2 methods to install django_twilio module on Heroku
1) Ran 'heroku run pip install django-twilio'
2) Added 'twilio==3.6.3' to requirements.txt and start the server on heroku.
When I run 'heroku run pip freeze' I can see the twilio entry. But when I go into python and run 'import django_twilio' I get a module not found error.
Please suggest how to fix this on heroku. Same steps worked fine on my local machine.
You didn't add the proper requirement, you only installed the twilio library. Your requirements.txt should include the following line:
django-twilio==0.4
Which will include all the other dependencies you'll need. The full pip freeze, after installing django-twilio looks like this:
Django==1.5.5
django-twilio==0.4
httplib2==0.8
six==1.4.1
twilio==3.6.3
unittest2==0.5.1
As a rule of thumb, always run pip freeze > requirements.txt before pushing an update to Heroku (assuming new dependencies were installed), to make sure you have a complete snapshot of your environment.