Install Spatialite for python (GeoDjango) on OS X

前端 未结 3 1776
南方客
南方客 2021-01-12 00:25

I am tearing my hair out trying to install Spatialite for GeoDjango!

I am already using Homebrew, it\'s generally easy and convenient so I initially tried to follow

相关标签:
3条回答
  • 2021-01-12 00:49

    I was able to get this working now, using the tip here:
    https://github.com/ghaering/pysqlite/issues/60#issuecomment-50345210

    I'm not sure if it was using the real paths that fixed it, or just the Homebrew kegs or underlying packages have been updated and now install cleanly. Still, it works now.

    I reproduce below the steps I took:

    brew update
    brew install sqlite  # 3.8.5
    brew install libspatialite  # 4.2.0
    brew install spatialite-tools  # 4.1.1
    
    git clone https://github.com/ghaering/pysqlite.git
    cd pysqlite
    

    (where brew reported I had existing versions I unlinked them and installed the latest as commented above)

    then edited setup.cfg to comment out #define=SQLITE_OMIT_LOAD_EXTENSION and specify the paths:

    include_dirs=/usr/local/opt/sqlite/include
    library_dirs=/usr/local/opt/sqlite/lib
    

    activated the virtualenv where I want it installed, then

    python setup.py build
    python setup.py install
    

    (build_static still fails with clang: error: no such file or directory: 'sqlite3.c')

    (maybe I should have done pip install . as suggested in the github issue)

    now the spatialite geodjango.db "SELECT InitSpatialMetaData();" succeeds, albeit with an ignorable error:

    InitSpatiaMetaData() error:"table spatial_ref_sys already exists"

    i.e. it's probably not even necessary to run that command

    0 讨论(0)
  • 2021-01-12 01:07

    When I was istalling this i follow this instructions https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/spatialite/#pysqlite2

    pysqlite2

    If you’ve decided to use a newer version of pysqlite2 instead of the sqlite3 Python stdlib module, then you need to make sure it can load external extensions (i.e. the required enable_load_extension method is available so SpatiaLite can be loaded).

    This might involve building it yourself. For this, download pysqlite2 2.6, and untar:

    $ wget https://pypi.python.org/packages/source/p/pysqlite/pysqlite-2.6.3.tar.gz
    $ tar xzf pysqlite-2.6.3.tar.gz
    $ cd pysqlite-2.6.3
    

    Next, use a text editor (e.g., emacs or vi) to edit the setup.cfg file to look like the following:

    [build_ext]
    #define=
    include_dirs=/usr/local/include
    library_dirs=/usr/local/lib
    libraries=sqlite3
    #define=SQLITE_OMIT_LOAD_EXTENSION
    
    0 讨论(0)
  • 2021-01-12 01:10

    I had the same error: SQLite header and source version mismatch.

    For me it was enough to update libsqlite3-dev.

    After that invoking $ spatialite geo.db "SELECT InitSpatialMetaData();" creates proper database.

    0 讨论(0)
提交回复
热议问题