Postgresql with Postgis Geodjango Installation - django

I'm trying to get Geodjango set up with Postgis but cannot enable the Postgis extension in the database. I am following the settings that are found on the Geodjango Documentation, but when I hit this step:
mydb=# CREATE EXTENSION postgis;
I get the following error:
ERROR: could not open extension control file "/usr/local/Cellar/postgresql/9.3.1/share/postgresql/extension/postgis.control": No such file or directory
Is this a problem with my paths? If so, how do I fix it? I found that my postgresql is located here:
admins-macbook:postgis-2.1.0 Admin$ find . -iname postgresql
./java/jdbc/src/org/postgresql
./java/jdbc/stubs/org/postgresql
Thanks for any ideas that will help!

First I'd check if the files exists at all on your system with: find /usr -name postgis.control
Chances are it doesn't exist...
I believe this is a problem with the way 9.3.1 is packaged.
Look in /usr/pgsql-9.3/share/contrib/postgis-2.1 (change this path according to your postgis version)
If you see files in here like postgis.sql and spatial_ref_sys.sql then you can manually create a spatial database template using the instructions here: https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/postgis/#creating-a-spatial-database-template-for-earlier-versions
You will just have to change POSTGIS_SQL_PATH to point to the .sql files mentioned above.

Related

libgsl.so.25: cannot open shared object file: No such file or directory Google Colab project

I'm using Google Colab to compile and run some code in CUDA and C++ (mostly because I dont have a CUDA capable GPU). For reference, the project Im trying to replicate is here:
https://github.com/franrruiz/shopper-src
For the project I need to install and configure the GSL Library, which I have done by following these steps:
Download GSL library from ftp://ftp.gnu.org/gnu/gsl/
Upload zipped file into Colab
Run the following code in Colab
# Unzip and change directory
!unzip "gsl-2.6.zip"
%cd "/content/gsl-2.6"
# Gives permissions
!chmod 755 "/content/gsl-2.6/configure"
# Configure
!./configure
!make
!make check
!make install
Compiling the code works perfectly fine, but when I attempt to run the code on a workable dataset I get the following error:
/content/shopper: error while loading shared libraries:
libgsl.so.25: cannot open shared object file: No such file or directory
What I've already Tried
!export LD_LIBRARY_PATH="/contents/gsl-2.6/.libs"
and
!export LD_LIBRARY_PATH="/usr/local/lib/"
However, neither of them fixed the issue. If it's helpful,
!sudo find / -name "libgsl.so.25"
returns
/usr/local/lib/libgsl.so.25
/content/gsl-2.6/.libs/libgsl.so.25
So we know the files exist. I just cant seem to point my code to it correctly.
Thanks in advance
I have the same issue with a different library. I also tried the export, which does not work, seems like the python in colab does not read environmental variables.
My solution is the following
!ln -s /usr/local/lib/<your_shared_library> /usr/lib/<your_shared_library>

Error in locating and reading specific .env file, in django project

In my project, I just added new security methods, separating the .env from the project into another folder and adopting the use of new processes. To do this, I followed the python-dotenv lib documentation, which I use in my app.
But even following the suggestion I can not find all the parameters, since I end up having the following error:
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty
My settings:
from dotenv import load_dotenv
env_path = Path('/home/user/configs') / '.env'
load_dotenv(dotenv_path=str(env_path))
How can I resolve this problem from the specific path?
Note: I use in my project, python 3.4.5 and django 1.9.4, but I do not believe that the problem is caused by the old versions adopted in the project.
Another important detail is that the .env file is correct, because when I use it in the same folder where I find the file settings.py it works without problems!
I'm also using this approach and from past few months I'm following a very good developer and he also writes about a python dependency "python-decouple" and you will going to get it in detail at this link
I think this will definitely going to solve your problem.
Python-decouple github repo : here
You can add the folder containing .env to the path. Here's how I did it:
load_dotenv(os.path.join(BASE_DIR, "project", ".env"))
Answered it here.

Django CompileError: File to import not found or unreadable: bootstrap-sass/assets/stylesheets/bootstrap/variables

I am currently working on the cadasta - an open source organisation's - Django project.
They require you to run their platform in a virtual machine (virtualbox) using vagrant.
As I enter their repository, and run their server using ./runserver, I am all of a sudden getting a CompileError which says:
File to import not found or unreadable: bootstrap-sass/assets/stylesheets/bootstrap/variables. Parent style sheet: /vagrant/cadasta/core/static/css/_variables.scss.
on line 74 of core/static/css/_variables.scss
#import "bootstrap-sass/assets/stylesheets/bootstrap/variables";
Following this link: https://github.com/jrief/djangocms-cascade/issues/130,
I found that libsass is already installed, and so I tried installing bootstrap-sass inside the VM, but it did no good. Everything was working fine until I renamed the cadasta-platform directory (i.e their github repo that I cloned, and so the main project is included inside this folder only.) and refreshed. I even tried running the server again, but couldn't get through this error. I suppose renaming the directory shouldn't be the cause?
I have no clue on how to proceed. Please help.
EDIT: After renaming the project folder to the same name solved this error. If anyone would ever like to answer this question, please explain why renaming the project directory produces an error like this? As I believe, I think renaming should not be an issue?

Building PostgreSQL driver for Qt

I trying to build psql driver but have some unexpected messages.
maxim#maxim-VirtualBox:~/Downloads/distrib/qt-everywhere-opensource-src-5.2.1/qtbase/src/plugins/sqldrivers/psql$ qmake psql.pro
Cannot read
/home/maxim/Downloads/qt-everywhere-opensource-src-5.2.1/qtbase/mkspecs/modules-inst/qt_lib_bootstrap_private.pri:
No such file or directory
...
Cannot read
/home/maxim/Downloads/qt-everywhere-opensource-src-5.2.1/qtbase/mkspecs/modules-inst/qt_lib_xml_private.pri:
No such file or directory
But all of these files exist. What is the problem?
The problem seems to be that you have "modules-inst" as the subfolder name, whereas it is only "modules" without the "-inst" suffix in reality.
See how it works fine on my end:
lpapp ~/Downloads/qt-everywhere-opensource-src-5.2.1/qtbase/src/plugins/sqldrivers/psql $ qmake psql.pro
lpapp ~/Downloads/qt-everywhere-opensource-src-5.2.1/qtbase/src/plugins/sqldrivers/psql $
I found a problem. After install qt-libraries I created new folder 'distrib' and move sources in there. That's why I got this problem.
I should have checked the existence of the directory by cd command.

Trying to get MySQL-python working for django using apache/FastCGI with no root access

My overall goal is to get django running on a server for which I don't have root access. I have convinced the admin to install mod_fcgid on the main apache server, but that is basically all I can do from the root side.
After a lot of struggling, my current setup is to create a virtualenv, install django, flup and MySQLdb-python in the virtualenv and make a "mysite.fcgi" script in a web accessible directory for which the .htaccess file uses fastcgid for .fcgi files. This all works and when I use a browser to load mysite.fcgi, then my django project is successfully reached - I know this because I get a django error page (instead of the countless "premature end of script headers" 500 pages I was getting while trying to figure out all the paths).
So, the django error page I am getting says:
ImproperlyConfigured at /
Error loading MySQLdb module: libmysqlclient.so.18: cannot open shared object file: No such file or directory
However, I know that everything basically works, since I can do "python manage.py runserver" as long as I add this line to my bash shell before running:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/alternate_versions/mysql-5.5.11/lib
Thus, I tried adding this to my .htaccess file:
SetEnv LD_LIBRARY_PATH /opt/alternate_versions/mysql-5.5.11/lib
But, that does not affect my django error message (other than showing the correctly set environment variable in the bottom of the django debug screen). I don't know why this doesn't work.
This leads me back to the MySQLdb-python package. I built that by downloading the source and running "python setup.py build" and "python setup.py install" from within my virtualenv. However, THIS IS MAYBE THE KEY PROBLEM: I need to use a mysql installation which is not the system default! The default installation does not have the source nor the mysql_config command. The alternate install is newer and has the source/devel version, which is required for mysql-python. So, in the site.cfg file for MySQLdb-python I had to specify the mysql_config variable to point at the alternate mysql installation:
mysql_config = /opt/alternate_versions/mysql-5.5.11-src/scripts/mysql_config
When I run mysql_config using the --libs option, it is (correctly?) pointing to the directory in which the libmysqlclient.so.18 file lives:
-L/var/alternate_versions/mysql-5.5.11/lib -lmysqlclient -lpthread -lz -lm -lrt -ldl
Ideas for moving forward:
Is there an alternate way to build the MySQLdb libraries? I tried the various options in the site.cfg file (static=True, embedded=True), but this doesn't work either. I didn't try all combinations of those options, since I don't really know what they are doing.
Can I manually add the path to the MySQLdb library? I think it is in an egg file, which I have no idea how to modify.
If MySQLdb was installed as root, would that make a difference? I want to be confident in this option before asking the admin to try it. We still have the problem of needing the alternate mysql installation.
Is there a different way to specify the LD_LIBRARY_PATH for apache?
Thanks for any suggestions.
Ok, I solved my problem by cheating. I downloaded a rpm for my version of Suse, got out the files using this command:
rpm2cpio python-mysql-1.2.2-1.79.x86_64.rpm | cpio -idmv
Then, I copied all the files to my virtualenv directory:
cp -pir ./usr/lib64/python2.6/site-packages/* ../virt/lib/python2.6/site-packages/
And, it worked!