Forums

geo aware database Geodjango

Hi sorry if this is a completely newb tard question. I want to use this Django-Leaflet-Storage plugin for leflet map

https://github.com/yohanboniface/django-leaflet-storage

I think it requires setting up Geodjango but I have no clue how or what server service I need. Will I be able to use PA to run everything I need ? And if so what would be the best package for a beginner like me.

Regards

Jay

From the geodjango docs, I believe you can use geodjango with our MySQL database. You could also use spacialite with sqlite as the database.

Think I need to now Install Geospatial libraries.

I tried to first install GEOS and got this error

configure: error: no acceptable C compiler found in $PATH See `config.log' for more details.

?

Right now we don't supply a C compiler on PythonAnywhere -- it's on our list, and I've upvoted it.

But I think we already have GEOS installed -- were you getting an error message that suggested that the system can't find it?

Ok thanks, this is all new to me. So is GEOS, GDAL, PROJ.4, SpatiaLite already installed. ?

I am working from the geodjango tuts and assumed I had to set everything up before I pip installed Django-Leaflet-Storage maybe everything is ready to go. ?

Update - I just tried and pip install django-leaflet-storage it came up with this error at the end? error: could not create '/usr/local/lib/python2.7/site-packages/leaflet_storage' : Read-only file system

You need to use the --local flag with pip

I tried pip install --local django-leaflet-storage

But it now says, You must give at least one requirement to install.

I think rcs1000 meant the --user flag.

Here's what I get with that:

16:52 ~ $ pip install --user django-leaflet-storage
Downloading/unpacking django-leaflet-storage
Downloading django-leaflet-storage-0.1.0.tar.gz (1.1MB): 1.1MB downloaded
Running setup.py egg_info for package django-leaflet-storage
Downloading/unpacking Django>=1.4 (from django-leaflet-storage)
Downloading Django-1.4.3.tar.gz (7.7MB): 7.7MB downloaded
Running setup.py egg_info for package Django
Requirement already satisfied (use --upgrade to upgrade): psycopg2>=2.4.5 in /usr/local/lib/python2.7/site-packages (from django-leaflet-storage)
Requirement already satisfied (use --upgrade to upgrade): PIL in /usr/local/lib/python2.7/site-packages/PIL (from django-leaflet-storage)
Requirement already satisfied (use --upgrade to upgrade): south in /usr/local/lib/python2.7/site-packages (from django-leaflet-storage)
Installing collected packages: django-leaflet-storage, Django
Running setup.py install for django-leaflet-storage
Running setup.py install for Django
changing mode of build/scripts-2.7/django-admin.py from 664 to 775
changing mode of /home/giles/.local/bin/django-admin.py to 775
Successfully installed django-leaflet-storage Django
Cleaning up...
17:14 ~ $

One thing that's worth noting is that this will switch you to using Django 1.4. We've not tested this outside a virtualenv, so it might not work. Let us know if what and we'll see what we can do.

Thanks giles, I had figured to use the --user flag, Is it ok to have all them directory's where they are now ? I added leaflet-storage to my INSTALLED_APPS and included the leaflet_storage urls. Then run python manage.py syncdb

21:33 ~/mysite $ python manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table leaflet_storage_licence
Creating table leaflet_storage_tilelayer
Creating table leaflet_storage_map_editors
Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/home/steadyjay/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 459, in     execute_manager
    utility.execute()
  File "/home/steadyjay/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/steadyjay/.local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/steadyjay/.local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/home/steadyjay/.local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/home/steadyjay/.local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 91, in handle_noargs
     sql, references = connection.creation.sql_create_model(model, self.style, seen_models)
   File "/home/steadyjay/.local/lib/python2.7/site-packages/django/db/backends/creation.py", line 44, in sql_create_model
     col_type = f.db_type(connection=self.connection)
   File "/home/steadyjay/.local/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py", line 200, in db_type
     return connection.ops.geo_db_type(self)
 AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
 21:34 ~/mysite $ 'DatabaseOperations' object has no attribute 'geo_db_type'AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
 -bash: DatabaseOperations: command not found
 21:41 ~/mysite $ 21:34 ~/mysite $ 'DatabaseOperations' object has no attribute 'geo_db_type'  return connection.ops.geo_db_type(self)
 -bash: syntax error near unexpected token `('
 21:34 ~/mysite $ 'DatabaseOperations' object has no attribute 'geo_db_type'AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
 21:41 ~/mysite $ AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
 -bash: AttributeError:: command not found
 21:41 ~/mysite $ 21:34 ~/mysite $ 'DatabaseOperations' object has no attribute 'geo_db_type'AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'

?

Looks like there's some incompatibility with the database. Could you post the DATABASES part of your settings.py (with passwords and such removed, of course)?

Can I request a complete reset please. I would like to restart my PA from fresh if possible.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'bigtits',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }

OK. Just this once, though.

So glad I found this post, this is exactly what Iḿ trying to do. I just installed django-leaflet-storage, but I have no idea on how to use this library, I have no idea on how to get useful info off of github.

Any chance you could point me to a good tutorial o countinue posting steps here? :D

Well, what have you tried so far? Have you got so far as completing the steps in the basic usage part of the github page? https://github.com/yohanboniface/django-leaflet-storage.

I'm currently stuck on installing spatialite (I tried running the command 'spatialite' from the shell and it's not there) I downloaded the library, but I wasn't able to compile it since there is no c compiler, I do have spatialite on my computer (got the 3.0 version through apt-get)

The spatialite library is in my home folder, is there a way an admin can run ./configure make make install ?

same for geos, it's not installed

I tried to install pysqlite using: pip install --user pysqlite but that failed because of the missing c compiler as well

as for the instalation of django-storage, I got to the same part as you, where syncdb fails because there's no spatial library: AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'.

From what I read, ENGINE has to change to 'django.contrib.gis.db.backends.spatialite', and also the SPATIALITE_LIBRARY_PATH has to be set in settings.py, once it's installed obviously

http://stackoverflow.com/questions/6055726/error-when-using-geodjango-with-spatialite-on-ubuntu

Looks like we'll need to install spacialite and geos. I'll raise a ticket so we can get that done.

Thankyou so much!! :)

Did you guys already install spacialite and geos? I am stuck on a project because these libraries are missing and I cannot sudo instaall them manually

Unfortunately not, but I've bumped the ticket to get them installed -- various changes we've made since the last post on this thread mean that it should be easier to do now. I'll see if we can get it into our next release (which unfortunately won't be for a few weeks now.)

Hi guys, great site! I've only just created an account and completely new here, but already really impressed!

Does anyone know if spatialite is supported now?

It is not installed by default and it's not on PyPI, but you can get it from the github repository and it installs and works on PythonAnywhere.

hi summer01, welcome!

Hi Glenn,

Thanks for your quick feedback and for the helpful link to the [github repository][1]. I tried pip install pyspatialite (as instructed from site) from a virtual environment and quickly became unstuck (see error below). I've since upgrade my pip version with no success. Here is the error:

You are using pip version 6.0.8, however version 6.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting pyspatialite
  Using cached pyspatialite-3.0.1-alpha-0.tar.gz
    /usr/local/lib/python2.7/dist-packages/setuptools/dist.py:283: UserWarning: The version specified requires normalization, consider using '3.0.1a0' instead of '3.0.1-alpha-0'.
      self.metadata.version,
Installing collected packages: pyspatialite
  Running setup.py install for pyspatialite
    /usr/local/lib/python2.7/dist-packages/setuptools/dist.py:283: UserWarning: The version specified requires normalization, consider using '3.0.1a0' instead of '3.0.1-alpha-0'.
      self.metadata.version,
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-kBbqxo/pyspatialite/setup.py", line 309, in <module>
        main()
      File "/tmp/pip-build-kBbqxo/pyspatialite/setup.py", line 306, in main
        setup(**get_setup_args())
      File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
        dist.run_commands()
      File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/usr/local/lib/python2.7/dist-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/usr/lib/python2.7/distutils/command/install.py", line 601, in run
        self.run_command('build')
      File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/usr/lib/python2.7/distutils/command/build.py", line 128, in run
        self.run_command(cmd_name)
      File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/usr/local/lib/python2.7/dist-packages/setuptools/command/build_ext.py", line 50, in run
        _build_ext.run(self)
      File "/usr/lib/python2.7/distutils/command/build_ext.py", line 337, in run
        self.build_extensions()
      File "/usr/lib/python2.7/distutils/command/build_ext.py", line 446, in build_extensions
        self.build_extension(ext)
      File "/tmp/pip-build-kBbqxo/pyspatialite/setup.py", line 175, in build_extension
        self.check_header(ext,"proj_api.h")
      File "/tmp/pip-build-kBbqxo/pyspatialite/setup.py", line 154, in check_header
        raise HeaderNotFoundException("cannot find %s, bailing out" % header)
    __main__.HeaderNotFoundException: cannot find proj_api.h, bailing out
    Complete output from command /usr/local/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip-build-kBbqxo/pyspatialite/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-r2YI0s-record/install-record.txt --single-version-externally-managed --compile:
    /usr/local/lib/python2.7/dist-packages/setuptools/dist.py:283: UserWarning: The version specified requires normalization, consider using '3.0.1a0' instead of '3.0.1-alpha-0'.

      self.metadata.version,

    running install

    running build

    running build_py

    creating build

    creating build/lib.linux-x86_64-2.7

    creating build/lib.linux-x86_64-2.7/pyspatialite

    copying lib/pyspatialite/dbapi2.py -> build/lib.linux-x86_64-2.7/pyspatialite

    copying lib/pyspatialite/__init__.py -> build/lib.linux-x86_64-2.7/pyspatialite

    copying lib/pyspatialite/dump.py -> build/lib.linux-x86_64-2.7/pyspatialite

    running build_ext

    Traceback (most recent call last):

      File "<string>", line 1, in <module>

      File "/tmp/pip-build-kBbqxo/pyspatialite/setup.py", line 309, in <module>

        main()

      File "/tmp/pip-build-kBbqxo/pyspatialite/setup.py", line 306, in main

        setup(**get_setup_args())

      File "/usr/lib/python2.7/distutils/core.py", line 151, in setup

        dist.run_commands()

      File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands

        self.run_command(cmd)

      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command

        cmd_obj.run()

      File "/usr/local/lib/python2.7/dist-packages/setuptools/command/install.py", line 61, in run

        return orig.install.run(self)

      File "/usr/lib/python2.7/distutils/command/install.py", line 601, in run

        self.run_command('build')

      File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command

        self.distribution.run_command(command)

      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command

        cmd_obj.run()

      File "/usr/lib/python2.7/distutils/command/build.py", line 128, in run

        self.run_command(cmd_name)

      File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command

        self.distribution.run_command(command)

      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command

        cmd_obj.run()

      File "/usr/local/lib/python2.7/dist-packages/setuptools/command/build_ext.py", line 50, in run

        _build_ext.run(self)

      File "/usr/lib/python2.7/distutils/command/build_ext.py", line 337, in run

        self.build_extensions()

      File "/usr/lib/python2.7/distutils/command/build_ext.py", line 446, in build_extensions

        self.build_extension(ext)

      File "/tmp/pip-build-kBbqxo/pyspatialite/setup.py", line 175, in build_extension

        self.check_header(ext,"proj_api.h")

      File "/tmp/pip-build-kBbqxo/pyspatialite/setup.py", line 154, in check_header

        raise HeaderNotFoundException("cannot find %s, bailing out" % header)

    __main__.HeaderNotFoundException: cannot find proj_api.h, bailing out

    ----------------------------------------
    Command "/usr/local/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip-build-kBbqxo/pyspatialite/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-r2YI0s-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-kBbqxo/pyspatialite

Any insight would be greatly appreciated. Thanks in advance!

Either install it into a virtualenv, or use pip install --user pyspatialite

Hi Glenn, many thanks for your advice. I'm getting the above error regarding __main__.HeaderNotFoundException: cannot find proj_api.h, bailing out which ever option I try.

I still can't get a pyspatialite install to fail like that. Please post the steps that you took to get that error.

Hi Glenn, again a massive thanks for helping with this.

Below are my steps that I've been following to create a test virtual environment.

source virtualenvwrapper.sh
mkvirtualenv testenv               #create testenv virtual environment
workon testenv                      # activate testenv
pip install pyspatialite            # with testenv activated, install pyspatialite using pip

Generates the following error.

You are using pip version 6.0.8, however version 6.1.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting pyspatialite   Using cached pyspatialite-3.0.1-alpha-0.tar.gz
    /home/honeybaj/.virtualenvs/testenv/local/lib/python2.7/site-packages/setuptools/dist.py:283: UserWarning: The version specified requires normalization, consider using '3.0.1a0' instead of '3.0.1-alpha-0'.
      self.metadata.version, Installing collected packages: pyspatialite   Running setup.py install for pyspatialite
    /home/honeybaj/.virtualenvs/testenv/local/lib/python2.7/site-packages/setuptools/dist.py:283: UserWarning: The version specified requires normalization, consider using '3.0.1a0' instead of '3.0.1-alpha-0'.
      self.metadata.version,
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-vns3bY/pyspatialite/setup.py", line 309, in <module>
        main()
      File "/tmp/pip-build-vns3bY/pyspatialite/setup.py", line 306, in main
        setup(**get_setup_args())
      File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
        dist.run_commands()
      File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/home/honeybaj/.virtualenvs/testenv/local/lib/python2.7/site-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/usr/lib/python2.7/distutils/command/install.py", line 601, in run
        self.run_command('build')
      File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/usr/lib/python2.7/distutils/command/build.py", line 128, in run
        self.run_command(cmd_name)
      File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/home/honeybaj/.virtualenvs/testenv/local/lib/python2.7/site-packages/setuptools/command/build_ext.py", line 50, in run
        _build_ext.run(self)
      File "/usr/lib/python2.7/distutils/command/build_ext.py", line 337, in run
        self.build_extensions()
      File "/usr/lib/python2.7/distutils/command/build_ext.py", line 446, in build_extensions
        self.build_extension(ext)
      File "/tmp/pip-build-vns3bY/pyspatialite/setup.py", line 175, in build_extension
        self.check_header(ext,"proj_api.h")
      File "/tmp/pip-build-vns3bY/pyspatialite/setup.py", line 154, in check_header
        raise HeaderNotFoundException("cannot find %s, bailing out" % header)
    __main__.HeaderNotFoundException: cannot find proj_api.h, bailing out
    Complete output from command /home/honeybaj/.virtualenvs/testenv/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip-build-vns3bY/pyspatialite/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-rZkINm-record/install-record.txt
--single-version-externally-managed --compile --install-headers /home/honeybaj/.virtualenvs/testenv/include/site/python2.7:
    /home/honeybaj/.virtualenvs/testenv/local/lib/python2.7/site-packages/setuptools/dist.py:283: UserWarning: The version specified requires normalization, consider using '3.0.1a0' instead of '3.0.1-alpha-0'.

      self.metadata.version,

    running install

    running build

    running build_py

    creating build

    creating build/lib.linux-x86_64-2.7

    creating build/lib.linux-x86_64-2.7/pyspatialite

    copying lib/pyspatialite/dbapi2.py -> build/lib.linux-x86_64-2.7/pyspatialite

    copying lib/pyspatialite/__init__.py -> build/lib.linux-x86_64-2.7/pyspatialite

    copying lib/pyspatialite/dump.py -> build/lib.linux-x86_64-2.7/pyspatialite

    running build_ext

    Traceback (most recent call last):

      File "<string>", line 1, in <module>

      File "/tmp/pip-build-vns3bY/pyspatialite/setup.py", line 309, in <module>

        main()

      File "/tmp/pip-build-vns3bY/pyspatialite/setup.py", line 306, in main

        setup(**get_setup_args())

      File "/usr/lib/python2.7/distutils/core.py", line 151, in setup

        dist.run_commands()

      File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands

        self.run_command(cmd)

      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command

        cmd_obj.run()

      File "/home/honeybaj/.virtualenvs/testenv/local/lib/python2.7/site-packages/setuptools/command/install.py", line 61, in run

        return orig.install.run(self)

      File "/usr/lib/python2.7/distutils/command/install.py", line 601, in run

        self.run_command('build')

      File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command

        self.distribution.run_command(command)

      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command

        cmd_obj.run()

      File "/usr/lib/python2.7/distutils/command/build.py", line 128, in run

        self.run_command(cmd_name)

      File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command

        self.distribution.run_command(command)

      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command

        cmd_obj.run()

      File "/home/honeybaj/.virtualenvs/testenv/local/lib/python2.7/site-packages/setuptools/command/build_ext.py", line 50, in run

        _build_ext.run(self)

      File "/usr/lib/python2.7/distutils/command/build_ext.py", line 337, in run

        self.build_extensions()

      File "/usr/lib/python2.7/distutils/command/build_ext.py", line 446, in build_extensions

        self.build_extension(ext)

      File "/tmp/pip-build-vns3bY/pyspatialite/setup.py", line 175, in build_extension

        self.check_header(ext,"proj_api.h")

      File "/tmp/pip-build-vns3bY/pyspatialite/setup.py", line 154, in check_header

        raise HeaderNotFoundException("cannot find %s, bailing out" % header)

    __main__.HeaderNotFoundException: cannot find proj_api.h, bailing out

    ----------------------------------------
    Command "/home/honeybaj/.virtualenvs/testenv/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip-build-vns3bY/pyspatialite/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-rZkINm-record/install-record.txt
--single-version-externally-managed --compile --install-headers /home/honeybaj/.virtualenvs/testenv/include/site/python2.7" failed with error code 1 in /tmp/pip-build-vns3bY/pyspatialite

Again, any help would be greatly appreciated and many thanks in advance!

Looks like they've broken their installer I'm afraid. You can track it on this issue: https://github.com/lokkju/pyspatialite/issues/22 -- maybe reply with a +1 so you can find out if/when they fix it?

You could try randomly picking older versions of their source tree from the github repo until you find the most recent one that installs successfully? I got this one to work:

pip install https://github.com/lokkju/pyspatialite/archive/e472bc5c51fd39c9c4f67ff46b2e4024e9af0e3a.zip

Harry, your install link worked (heartfelt thanks), but still ran into the following when running python manage.py migrate with my django project.

'The pysqlite library does not support C extension loading. '
django.core.exceptions.ImproperlyConfigured: The pysqlite library does not support C extension loading. Both SQLite and pysqlite must be configured to allow the loading of extensions to use SpatiaLite.

I've seen some similar threads on google so will start looking around there for any solutions.

Thanks Glenn and Harry for your support.

Hi there,

just in case anyone else comes across this old thread, we have pyspatialite preinstalled for python2, and the spatialite C library is available for any python 3 libraries that want to use it (eg geodjango). More info here