Could not find the GDAL library (connection with Hana) - python

I am using Python 3.8.5 version and the Django 3.2.4. I already install GDAL library from the official website with the version 3.3.0. with a pip install.
There are 4 databases presents at the origin in Django but I have to use the Hana one which is notpython. I have only found 2 topics relative to that on GitHub but they are both very old (4 years and 8 years ago).
I have tried everything to solve that problem but nothing seems to work. I already have the following message when I try to make migrations :
"django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal302", "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings."
Someone has an idea to solve that problem ?

django don't use gdal python binding. It only require the share library libgdal.so, so you need to have libgdal.so installed somewhere on your system.
Next if gdal is not installed in system directory (ie installed with your distribution package manager), django most of the time is not able to find it, even if the path is in your LD_LIBRARY_PATH.
You have to configure it explicitly in the django settings, as well as geos which is also required:
# django settings of your project
GEOS_LIBRARY_PATH = "/custom/install/prefix/lib/libgeos_c.so"
GDAL_LIBRARY_PATH = "/custom/install/prefix/lib/libgdal.so"
Take a look at https://docs.djangoproject.com/fr/3.2/ref/contrib/gis/install/geolibs/

Related

How to install and point to Python GDAL library on App Engine (Standard)?

Django is firing this error locally:
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal3.2.0", "gdal3.1.0", "gdal3.0.0", "gdal2.4.0", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
Here's an example of how the path should look in settings:
GDAL_LIBRARY_PATH = r'C:\OSGeo4W64\bin\gdal300'
Now this is an easy, well documented fix locally, but we're quite far along with App Engine Standard on GCP (Python 3). There's a GDAL package that seems to be installable by pip but it also seems there's also native extensions/headers required.
How can I meet this requirement?
Can I install GDAL in app engine either in a specific directory or install with an understanding of where it is?
Note: Willing to do any kind of workaround like host it remotely (probably not allowed) or even try a different library for lat-long distance filtering. Though for the latter it must accept and return a queryset via queryset.filter() in Django so I doubt there are other Django options. Perhaps running PSQL query directly on a queryset?
The only solution I found and examined were vendor packages and lib. But it looks like this is no longer an option (https://cloud.google.com/appengine/docs/legacy/standard/python/tools/using-libraries-python-27#vendoring) for Python 3 for Standard.

Error "-fabi-version=2" when installing Msyqldb or Flask-mysqldb (or any mysql client) in PyCharm on Mac OS using AMPPS

I'm a beginner Python programmer and currently using pyCharm CE IDE on a MAC OS High Sierra system following a tutorial to create a database web-app.
The issue I am facing is when I try to add any mysql access library in 'requirements.txt' the installation fails. (tried with Flask-Mysqldb, mysqlclient, mysqldb)
I figured out that the issue i was facing earlier missing mysql_config was due to using AMPPS (Softaculous) MAMP stack and was able to fix it by updating my $PATH  variable to include the path to /Applications/AMPPS/mysql/bin
Now the error I am getting is
clang: error: unknown argument: '-fabi-version=2'
Most of the solutions I have come across are suggestions to replace MAMP MySQL with the homebrew version (or something similar). Ideally I would like to stick with AMPPS since I am familiar with this and have other apps currently hosted on it (e.g. Wordpress).
Resolved the issue by following the below steps:
modify mysql_config at /Applications/AMPPS/mysql/bin
Remove '-fabi-version=2' flag from 'cflags' (around line:122)
successfully install mysqlclient (or MySQLdb)

How to use lxml version 3.7.3 on app engine?

On their Built-in Third-party Libraries page, it says that lxml 3.7.3 is supported but I can't seem to find a way to use that.
If I write in app.yaml:
- name: lxml
version: latest
When I log etree.LXML_VERSION inside the app, I get (2, 3, 0, 0).
Setting the version specifically to "3.7.3" (instead of latest) doesn't seem to work. When I try to deploy, gcloud says:
ERROR: (gcloud.app.deploy) An error occurred while parsing file: [... /app.yaml]
lxml version "3.7.3" is not supported, use one of: "2.3", "2.3.5"
in "... app.yaml", line 17, column 1
I have installed lxml locally inside the ./lib folder, but the folder is ignored on deploy.
Am I doing something wrong?
The problems seemed to happen because of an old google cloud sdk.
The sdk was installed using apt-get and somehow it was not getting updated. This also included an older Python SDK
At this moment the latest Python SDK is 1.9.62, I was using 1.9.52.
Updating the sdk seemed to fix the problem
sudo apt-get update && sudo apt-get install google-cloud-sdk
It wouldn't be the 1st time that inconsistencies exist between the documentation, what's included in the cloud SDK, what's included in the GAE language specific SDK and what's actually available on GAE (in production). See, for example, PyCharm - Can't create App Engine Application using DJango.
The deployment error message you got suggests that the 3.7.3 version doesn't actually exist on GAE, despite being marked as available in the documentation.
The lxml library is on the list of a few special libraries which need extra attention. Most likely because they aren't "pure Python code with no C extensions" and thus they can't be included in the SDKs with the other libraries, so they need to be installed separately on your local system. From Using built-in bundled libraries with the local development server (check that entire section for related info):
Many of the built-in libraries provided by the runtime are
automatically available to the local development server. However, the
following built-in libraries must be installed locally before you can
use them with the local development server:
lxml
matplotlib
mysqldb
numpy
PIL
crcmod
pycrypto
Now, if you really want the 3.7.3 version, you may be out of luck: if indeed it's not "pure Python code with no C extensions" then you also won't be able to vendor it into your app either. Still, it's worth a try. A new try, note that you also need to:
take it out of the app.yaml file's libraries: section - you're not requesting a GAE-provided library anymore
complete the entire vendoring in procedure (you didn't mention creating the appengine_config.py file, for example).
If that doesn't work then you'll have to settle for one of the available versions mentioned in the deployment error messages. You'll need to:
add that version to the app.yaml file's libraries: section
install that version on your local system
drop the vendoring in attempt, if you went for it

"Unable to locate the SpatiaLite library." Django

I'm trying to make Django's SQLite3 accept spatial queries. This tutorial suggests that I add this to settings:
SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
Which produces this error:
django.core.exceptions.ImproperlyConfigured: Unable to load the
SpatiaLite library extension "mod_spatialite" because: The specified
module could not be found.
I also tried doing this :
SPATIALITE_LIBRARY_PATH = r'C:\\Program Files (x86)\\Spatialite\\mod_spatialite-4.3.0a-win-x86\\mod_spatialite-4.3.0a-win-x86\\mod_spatialite.dll'
If I don't add this variable I receive this error when I migrate:
django.core.exceptions.ImproperlyConfigured: Unable to locate the
SpatiaLite library. Make sure it is in your library path, or set
SPATIALITE_LIBRARY_PATH in your settings.
Thank you..
Amusingly enough 5 days later I'm having the same issue. After a little bit of poking around I got it working:
Set
SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
and extract ALL the DLL files from the mod_spatialite-x.x.x-win-x86.7z to your Python installation directory. The dll's apparently need to be in the same folder with python.exe. Also I imagine the mod_spatialite package needs to 32/64 bit according to your python installation. If you're missing some dll's, you get the same error "specified module not found" regardless of what dll file is missing, so it's a bit misleading.
Downloaded from http://www.gaia-gis.it/gaia-sins/
I used mod_spatialite stable version 4.3.0a x86 with Python 3.5.2 32-bit.
Other threads on the same issue with all sorts of answers:
Use spatialite extension for SQLite on Windows
Getting a working SpatiaLite + SQLite system for x64 c#
https://gis.stackexchange.com/questions/85674/sqlite-python-2-7-and-spatialite
On Ubuntu18.04,
adding SPATIALITE_LIBRARY_PATH = 'mod_spatialite.so'
with libsqlite3-mod-spatialite installed worked for me.
Note: The answer has mod_spatialite, while for me mod_spatialite.so worked.
This is how to install SpatiaLite (almost) inside virtualenv for Python 3:
Download cyqlite a special SQLite build with R-Tree enabled. It is required by GoeDjango.
Download mod_spatialite (Windows binaries are in the pink box at the bottom of the page) i.e. mod_spatialite-[version]-win-x86.7z
Unzip mod_spatialite files (flatten the tree and ignore the folder in the archive) into the virtuelenv Scripts folder.
This part I don't like but I not could find a workable solution without touching main Python3 installation.
Rename or otherwise backup c:\Python35\DLLs\sqlite3.dll
From cyqlite uznip sqlite3.dll file into the c:\Python35\DLLs\
Kudos: https://gis.stackexchange.com/a/169979/84121
I ran into this problem when trying to deploy GeoDjango on AWS Elastic Beanstalk. Turns out I needed to set SPATIALITE_LIBRARY_PATH = 'mod_spatialite.so' to SPATIALITE_LIBRARY_PATH = 'libspatialite.so' (installed at /user/lib64/libspatialite.so after running sudo yum install libspatialite and sudo yum install libspatialite-devel from my .ebextensions).
HOW ACTIVATE CORRECTLY SPATIALITE IN VIRTUAL DJANGO ENVIRONNEMENT IN WINDOWS OPERATING SYSTEM LIKE 7, 8, 10
I hope my answer will come to the safety of my developer friends who use Sqlite delivered by default in django to manage their geographic data by the spatialite link which is an extension also delivered by default in python (3 or +). I'm starting from the fact that you have a preconfigured virtual environment. The first thing to do is to download two zip: sqlite-dll-win32-x86-[version].zip and mod_spatialite-[version]-win-x86.7z and unzipp this in the same directory(overwrite if there are any conflicts)
Copy all previously unzipped files into your directory and paste them into your Scripts directory of your virtual environment
It all restart your pc if necessary, deactivate and reactivate your virtual environnement and code...

Does google app engine use python 2.7.0 or 2.7.1?

What python version does app engine use?
This is related to problems I'm having on mac osx with getting pycrypto to work. Because the python version now in mac is 2.7.1. When Google says the python version for app engine is '2.7' do they mean precisely 2.7.0? Or is python 2.7.1 okay too?
Can this cause problems for my local install of pycrypto? ( which I installed with pip: sudo pip install pycrypto==2.6 )The pycrypto library works correctly, but it somehow messes up app engine running a development server. The logging doesn't show all errors or logs which I expect to appear there.
When Google says the python version for app engine is '2.7' do they mean precisely 2.7.0? Or is python 2.7.1 okay too?
Any subversion of python 2.7 works. 2.7.0 works, but I have used 2.7.6 and 2.7.10 extensively as well. So I'm sure that 2.7.1 will work too.
Can this cause problems for my local install of pycrypto? ( which I installed with pip using: 'sudo pip install pycrypto==2.6' )The pycrypto library works correctly, but it somehow messes up app engine running a development server. The logging doesn't show all errors or logs which I expect to appear there.
I know you have asked about this before but I will give you an other (better) way to include pycrypto in your appengine project.
In your app.yaml, specify the following:
libraries:
- name: pycrypto
version: "2.6" # or "latest", or "2.3"
See https://cloud.google.com/appengine/docs/python/tools/libraries27 for more info about which libraries are supported by appengine and how you can import which versions.
It seems as though you're asking the question which inspired your title, about python verson 2.7.x, as a way to get insight into your actual problem, which is related to pycrypto. Tim's answer dealt with the question of which sub-versions of 2.7.x are supported.
It appears you're using both the app.yaml libraries stanza and pip to get an instance of pycrypto. So:
Is the pip-installed pycrypto residing on your dev-box somewhere like /usr/local/lib/python-2.7, or is it in the app's folder, specifically?
When the dev-server is running, is it possible your python path has it using the pycrypto installed by pip on your system, with that pycrypto being a different version than the one in production? This might cause different behaviour on the dev-server vs. production.
...All this said, it still seems odd, as Tim has pointed out, that you should see a disruption to logging based on this. What is it you're logging, and are you using any exception handling which might be dropping the responsibility to log?
Finally, is there a setting when running the dev-server which you can use that would enable more verbosity? Try that to see if you can raise the logging level enough to make the exceptions you're looking for visible.
These are my thoughts so far on how to get out of your jam.

Categories

Resources