在OS X上安装Spatialite for python(GeoDjango) [英] Install Spatialite for python (GeoDjango) on OS X

查看:580
本文介绍了在OS X上安装Spatialite for python(GeoDjango)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在撕裂我的头发,试图为GeoDjango安装Spatialite!



我已经在使用Homebrew,这通常很方便,所以我最初试图遵循<对于GeoDjango,一个href =https://docs.djangoproject.com/en/1.6/ref/contrib/gis/install/#homebrew =nofollow noreferrer> Homebrew说明。



但是,这不能安装任何数据库,即Spatialite。下一步是尝试安装Spatialite本身,但没有Django文档提供的Homebrew特定说明。



我发现这个教程看起来很完美 - 为GeoDjango提供了一个Homebrew和virtualenv友好的Spatialite安装。



但它不起作用...似乎我的 pysqlite 与非空间 - 启动版本的SQLite,而不是从Homebrew安装的Spatial-ised的,我在Django尝试连接到db时收到此错误:



pysqlite库不支持C扩展加载,SQLite和pysqlite必须配置为允许加载扩展才能使用SpatiaLite。



pysqlite的作者还没有回应我的请求h elp on Github ,我还没有通过Google发现任何东西。



所以我回到绘图板,决定遵循Mac OS X特定说明 在GeoDjango文档中...通过从KyngChaos二进制包安装各种地理库。



文档说按照它们的顺序安装包上面列出但是我发现无法安装 UnixImageIO 而不安装 PROJ 。文档中下载Spatialite二进制文件的链接( http:// www。 gaia-gis.it/spatialite-2.3.1/binaries.html )被破坏,所以我使用了KyngChaos的Spatialite Tools v4.1。



进入下一步我得到这个错误:

  $ spatialite geodjango.dbSELECT InitSpatialMetaData(); 
SQLite头和源版本不匹配
2013-10-17 12:57:35 c78be6d786c19073b3a6730dfe3fb1be54f5657a
2013-09-03 17:11:13 7dd4968f235d6e1ca9547cda9cf3bd570e1609ef

不知道这一点有什么问题。



还有别人在这里SO谁已经走了KyngChaos路线,只是最终使用相同的SQLite和pysqlite都必须配置为允许加载从Homebrew路由获得的扩展名错误。



我发现此门票#17756 添加 pyspatialite 支持Django - pyspatialite 应该是一个更简单的方法来 pip install 除了不幸的是, (请参阅机票底部的评论)。



我有点不情愿开始尝试从源代码中构建一切,因为它似乎可能会再次遇到相同的问题,但花费数小时Googling有关隐藏编译器错误,魔法标志和路径等的信息。



我准备放弃使用Postgres / PostGIS。

解决方案

我现在可以使用这里的提示来获得这个工作:

https://github.com/ghaering/pysqlite/issues/60#issuecomment-50345210



我不知道是否使用修复它的真正路径,或者只是Homebrew小桶或底层包已经更新,现在安装得很好。不过,现在可以工作了。



我复制下面的步骤:

  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

(其中brew报告我有现有的版本我取消链接他们,并安装最新的如上所述)



然后编辑 setup.cfg 要注释掉#define = SQLITE_OMIT_LOAD_EXTENSION 并指定路径:

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

激活了我想要安装的virtualenv,然后

  python setup.py build 
python setup.py install

build_static 仍然失败与 clang:错误:没有这样的文件或目录: sqlite3.c'



(也许我应该已经完成​​了 pip install。 as建议在github问题)



现在 spatialite geodjango.dbSELECT InitSpatialMetaData();成功,虽然有一个可忽略的错误:



InitSpatiaMetaData()错误:table spatial_ref_sys已经存在



ie这可能不需要运行该命令


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 the Homebrew instructions for GeoDjango.

But this stops short of installing any database, i.e. Spatialite. The next step is to try and install Spatialite itself, but there are no Homebrew-specific instructions provided by Django docs.

I found this tutorial which looks perfect - a Homebrew and virtualenv-friendly install of Spatialite for GeoDjango.

But it doesn't work... it appears that my pysqlite is linked against the non-spatial-enabled version of SQLite that comes with OS X, rather than the Spatial-ised one I installed from Homebrew, I get this error when Django tried to connect to the db:

"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."

The author of pysqlite hasn't responded to my pleas for help on Github and I haven't found anything via Google.

So I went back to the drawing board and decided to follow the "Mac OS X-specific instructions" in the GeoDjango docs... by installing the various geo libs from the KyngChaos binary packages.

The docs say "Install the packages in the order they are listed above" but I found I couldn't install UnixImageIO without installing PROJ first. The link in the docs to download Spatialite binaries (http://www.gaia-gis.it/spatialite-2.3.1/binaries.html) is broken so I used the "Spatialite Tools v4.1" from KyngChaos instead.

Proceeding to the next step I get this error:

$ spatialite geodjango.db "SELECT InitSpatialMetaData();"  
SQLite header and source version mismatch  
2013-10-17 12:57:35 c78be6d786c19073b3a6730dfe3fb1be54f5657a  
2013-09-03 17:11:13 7dd4968f235d6e1ca9547cda9cf3bd570e1609ef

Not really sure what's wrong at this point.

There is someone else here on SO who has gone the KyngChaos route and just ends up with the same "Both SQLite and pysqlite must be configured to allow the loading of extensions" error I got from the Homebrew route anyway.

I found this ticket #17756 for adding pyspatialite support to Django - pyspatialite is supposed to be an easier way to pip install everything but unfortunately it doesn't work either (see comments towards bottom of ticket).

I'm a bit reluctant to start trying to build everything from source by hand as it seems likely I'll just run into the same problems again, but spending hours Googling for info about cryptic compiler errors, magic flags and paths etc along the way.

I'm about ready to give up and just use Postgres/PostGIS.

解决方案

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

这篇关于在OS X上安装Spatialite for python(GeoDjango)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆