Postgis isn't an available database backend - django

I'm facing this error when setting up geodjango in a working django 1.9 app.
My app is living inside a amazon EC2 instance plus a RDS postgres instance.
The error is:
django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.postgis' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3
What I've done:
Install GEOS, PROJ.4 and PostGIS as described in geodjango doc.
Install PostGIS in amazon RDS as described in amazon doc.
Modify my project settings.py to include:
INSTALLED_APPS = (... 'django.contrib.admin', ... 'django.contrib.gis')
GEOS_LIBRARY_PATH = '/usr/local/lib/libgeos_c.so'
DATABASES = { ... 'ENGINE': 'django.contrib.gis.db.backends.postgis' ...}
Modify my app models.py to import models from django.contrib.gis.db, instead of django.db
Any guess what I'm missing?

I had the same issue
i installed the osgeo
and then navigated to the missing libraries
> # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR =
> os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> TEMPLATE_DIR=os.path.join(BASE_DIR,'templates')
and these were the missing libraries for me:
GDAL_LIBRARY_PATH = r'C:\OSGeo4W64\bin\gdal204.dll'
GEOS_LIBRARY_PATH=r'C:\OSGeo4W64\bin\geos_c.dll'

Run this command
sudo apt-get install binutils libproj-dev gdal-bin
This is described in this documentation

I had the same issue. I ran pip install gdal, which showed error messages about a libffi library missing on my system. After installing the correct library (libffi6 on AUR), I ran pip install gdal again and the issue was resolved.

I found that my libgdal library was causing me issues and giving me this error.
I'm working in windows under a conda environment running Django 1.11 and GDAL 2.0. Changing GDAL and django versions didnt seem to fix anything. However, setting the libgdal version to 1.11.2 seemed to clear the error up for me.

Related

Ubuntu 16.04 virtualenv django import error

I installed django at virtualenv.
Django is installed at '/usr/local/lib/python3.7/site-packages', but that's not virtualenv's python path. so that makes django import error in virtualenv.
please help
You should always install libraries within your virtualenv. Activate it and then do pip install django again.

ImportError: No module named 'django' despite having it installed running apache2 server

I know that many have posted similar question however I tried most solution without success.
I'm trying to host a webpage with apache2 and django in python3.
In the error log I found ImportError: No module named 'django' when accessing the wsgi.pyfile, where I also added import sys, sys.version to confirm which python version is used and from the error log I can see that I'm running following python version 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609].
When I run python3.5 I see that I uses the same python version and here I can run import django without any error!
EDIT: I checked django.__file__and saw that it was located in /home/USERNAME/.local/lib/python3.5/site-packages/django/init.py and that path /home/USERNAME/.local/lib/python3.5/site-packages wasn't in the sys.path that tried to run django. But adding it with sys.path.append(path) didn't help :(
Any thoughts what I might have messed up?
If you have Setup the whole configuration in VirtualEnv then , i suggest you to activate it by,
source /location to /env/bin activate
pip3 install django=version_id
or pip install django=version id
if you want to pass version id then its good or it will install the latest django from your repo.
Now test Django Version there.
Hope you will no get the error.
Location - means the path where env will be located in project directory, if you have followed the standard installation process of django or else you don't need, and version id- vesion of django framework.
I finally understood how to solve it! first I had to run pip3 uninstall django then run sudo pip3 install django.

Django REST Framework Import Error

I'm trying to install Django REST framework and I keep getting:
No module named 'rest_framework'
I've added:
'rest_framework' to my INSTALLED_APPS = []
I installed through pip3 and it still doesn't seem to be working.
This should not be the case. You might have installed globally or inside virtualenv.
Always installed your dependencies inside a virtualenv.
I think best way to get it working.
source <virtualenv>/bin/activate
pip install djangorestframework
Next whenever you work with your project re-enable back virtualenv.

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 storages: Import Error - no module named storages

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/