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.
Related
I have been looking around for an answer to this question, but everywhere I see the advice of running a pip install flask-wtf in the virtual environment. The requirements have already been satisfied in mine, but for some reason I am getting a missing module error. I am working on a school project building a website using flask and would really appreciate the help. My import is:
from flask_wtf import Form`
When I try to run the install command I get a message that says the requirement is already satisfied, as shown in this image.
Based on the screenshot, your flask-wtf and friends are installed outside virtualenvs, in the system site-packages directory.
It'd be a good idea to uninstall those from the global site-packages directory (python3 -m pip uninstall flask-wtf wtforms flask jinja2 click werkzeug markupsafe itsdangerous), create and activate a virtualenv (python3 -m venv my_venv and ./my_venv/bin/activate), then reinstall the dependencies within the virtualenv.
I have a django project using python 2.7 and want to deploy it on Google App Engine(GAE).
I followed all this link for the tutorial:
https://cloud.google.com/python/django/appengine
When I finished deploying, and go to my project URL, I got an error and when I look on the Error Reporting in Google Cloud Platform
It says "ImportError: No module named googleads", but I already installed it on my local before I uploaded it.
pip freeze:
asn1crypto==0.24.0
astroid==1.6.1
autopep8==1.3.4
backports.functools-lru-cache==1.5
cffi==1.11.5
colorama==0.3.9
configparser==3.5.0
cryptography==2.1.4
Django==1.11.11
enum34==1.1.6
futures==3.2.0
googleads==10.1.0
httplib2==0.10.3
idna==2.6
ipaddress==1.0.19
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
MySQL-python==1.2.5
mysqlclient==1.3.4
oauth2client==4.1.2
pyasn1==0.4.2
pyasn1-modules==0.2.1
pycodestyle==2.3.1
pycparser==2.18
pylint==1.8.2
PyMySQL==0.8.0
pyOpenSSL==17.5.0
PySocks==1.6.8
pytz==2018.3
PyYAML==3.12
rsa==3.4.2
singledispatch==3.4.0.3
six==1.11.0
suds-jurko==0.6
virtualenv==15.1.0
win-inet-pton==1.0.1
wrapt==1.10.11
xmltodict==0.11.0
Please help!
Thanks!
Note the -t lib difference between the 2 pip invocations in step 2 of the Run the app on your local computer section:
pip install -r requirements-vendor.txt -t lib/
pip install -r requirements.txt
The first one installs the runtime dependencies for your app - inside your app (see Copying a third-party library).
The 2nd one installs dependencies needed for the local development server - in your venv (or local system).
Having app dependencies installed in your venv or local system (which is what your pip freeze shows) doesn't help - that's not where the sandbox is looking at for your app's dependencies.
So check that the googleads package is in your equivalent of the requirements-vendor.txt file and that those packages are installed in your app's lib directory.
Good day.
I'm a newbie to Django and I have a slight confusion:
When deploying my Django app, do I need to deploy it with all the Python 'come-with' modules, or the hosts already have them installed.
Also, I installed PIL for image manipulation. Would they also have it installed or i have to find a way to install it on their servers. Thanks in advance
do I need to deploy it with all the Python 'come-with' modules
Never do that. It might conflict with the dependencies on the server. Instead issue the following command to create a dependency file (requirements.txt).
pip freeze > requirements.txt (issue this command where manage.py is located)
On the server create a new virtual environment. Now copy django project to the server (you can do this using git clone or just plain old Filezilla). Activate virtual environment. Then change you current working directory to the where manage.py is located. to install all the dependencies issue the following command.
pip install -r requirements.txt
This will install the required dependencies on on server.
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/
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.