简体   繁体   English

Mapnik导入问题OSX 10.6

[英]Mapnik import problems OSX 10.6

I'm very new at this (haven't even used Terminal before yesterday), but I'm trying to do some terrain mapping following Bjorn Sandvik's instructions at http://blog.thematicmapping.org/2012/07/terrain-mapping-with-mapnik.html . 我对此非常陌生(昨天以前甚至没有使用过Terminal),但是我正在按照Bjorn Sandvik在http://blog.thematicmapping.org/2012/07/terrain-mapping的说明进行一些地形映射-with-mapnik.html I've installed python and mapnik following the instructions on their respective sites as best I can understand, but when I try to import mapnik via python in Terminal I get an ImportError. 据我所知,我已经按照各自站点上的说明安装了python和mapnik,但是当我尝试在Terminal中通过python导入mapnik时,出现了ImportError。 Can anyone more experienced tell me how to fix the problem? 有经验的人可以告诉我如何解决该问题吗? It looks to me like it's calling a different version of python (if I just type python in Terminal instead of /usr/local/bin/python it returns 2.6), but I don't know what to do about that or where I went wrong in the installation process. 在我看来,它正在调用其他版本的python(如果我只是在Terminal中键入python而不是/ usr / local / bin / python它将返回2.6),但是我不知道该怎么办或我去了哪里在安装过程中出现错误。 I'm on Mac OSX 10.6, 64bit. 我使用的是Mac OSX 10.6(64位)。

$ mapnik-config -v
2.2.0
$ /usr/local/bin/python
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import mapnik
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/site-packages/mapnik/__init__.py", line 69, in <module> from _mapnik import *
ImportError: dlopen(/usr/local/lib/python2.6/site-packages/mapnik/_mapnik.so, 2): Symbol not found: __tlv_bootstrap
Referenced from: /usr/local/lib/libmapnik.dylib
Expected in: /usr/lib/libSystem.B.dylib
  in /usr/local/lib/libmapnik.dylib
  >>> 

UPDATE: In the hope that it would help (and since I'd been planning to do it anyway), I upgraded my OS to Mavericks, uninstalled all my Python versions from python.org following the instructions here: How to uninstall Python 2.7 on a Mac OS X 10.6.4? 更新:希望有帮助(并且由于我一直打算这样做),我将操作系统升级到Mavericks,按照以下说明从python.org卸载了我的所有Python版本: 如何在上卸载Python 2.7 Mac OS X 10.6.4? , then installed the current version of Xcode (it wasn't available without a $99 paid developer account at Apple for OSX 10.6.8), ran the commands listed below by William again to install homebrew, Python and mapnik, and tried to 'import mapnik' in Python again. ,然后安装了当前版本的Xcode(如果没有在OSX 10.6.8的Apple获得$ 99的付费开发者帐户,该版本将无法使用),再次运行William列出的以下命令来安装自制软件,Python和mapnik,并尝试“导入mapnik”。 Still didn't work, but I have a different error message now. 仍然没有用,但是我现在有不同的错误消息。

python
Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mapnik
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named mapnik
>>>

I ran brew doctor, there were far fewer Warnings this time and none seemed surprising. 我当了冲泡医生,这次的警告少了很多,而且似乎都还不足为奇。 I did take brew doctor's advice and tried resetting my PATH using their recommended code: 我确实接受了Brew医生的建议,并尝试使用他们推荐的代码重置PATH:

echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile

That didn't help either. 那也没有帮助。 My working directory is now Macintosh:bin home_directory$. 我的工作目录现在是Macintosh:bin home_directory $。

I also noticed an error at the end of the Python install: 我还注意到在Python安装结束时出现错误:

Error: Permission denied - /usr/local/lib/python2.7/site-packages/sitecustomize.py

This message re-appeared at the end of the mapnik install. 该消息在mapnik安装结束时再次出现。 Perhaps neither of these installed properly? 也许这些都没有正确安装? When I do mapnik-config -v it says 2.2.0. 当我执行mapnik-config -v时,它说的是2.2.0。 When I do python --version, it says 2.7.5. 当我执行python --version时,它说的是2.7.5。 When I look in /usr/local/bin I can see these files: mapnik-config, mapnik-speed-check. 当我查看/ usr / local / bin时,可以看到以下文件:mapnik-config,mapnik-speed-check。 I do not see any mapnik files when I look in /usr/bin. 在/ usr / bin中查看时,看不到任何mapnik文件。

UPDATE 2: IT WORKED! 更新2:工作正常! I just had to re-do the 'enable python bindings' thing in the mapnik README.txt file (I reset to my home directory first, not sure if that matters). 我只需要在mapnik README.txt文件中重新做“启用python绑定”(我先重置到我的主目录,不确定是否重要)。 This: 这个:

py_version=$(python -c "import sys;print('%s.%s' % (sys.version_info[0],sys.version_info[1]))")
    export PYTHONPATH=/usr/local/lib/python${py_version}/site-packages/:$PYTHONPATH

Seems to be working. 似乎正在工作。 Now I just have to fix my mapnik code & I should be ok! 现在,我只需要修复我的mapnik代码,就可以了! Many thanks to those who commented. 非常感谢那些发表评论的人。 I don't have enough 'reputation' to vote William's post up so if someone could do that it would be much appreciated! 我没有足够的“声誉”来投票支持威廉的职位,因此,如果有人可以这样做,将不胜感激!

即使在brew安装之后,您也必须像这样手动导出绑定

export PYTHONPATH="/usr/local/lib/python2.7/site-packages"

You are correct, you have Python versions clashing. 没错,Python版本发生冲突。 Since you are on OSX and you haven't really used terminal before, it is not going to be one 'easy fix'. 由于您使用的是OSX,并且以前从未真正使用过terminal ,因此它不会是一个“简单的解决方案”。 I recommend you read this book http://linuxcommand.org/tlcl.php , to understand how to use the command line properly. 我建议您阅读http://linuxcommand.org/tlcl.php这本书,以了解如何正确使用命令行。 Note: even though it is for Linux, it is for the BASH shell, which is used by default in OSX. 注意:即使它是用于Linux的,它也用于BASH Shell,它在OSX中默认使用。

The reason you get Python 2.6 when you type only python is because the directory holding the executable for that version of python is listed before the directory holding the executable for Python 2.7 in the $PATH environment variable. 仅键入python时得到Python 2.6的原因是,在$PATH环境变量中,列出了保存该版本python可执行文件的目录,该目录被列出。 That also means when you installed mapnik it most likely installed that module in the site-packages for Python 2.6 and bound it to that version. 这也意味着,当您安装mapnik ,很可能mapnik模块安装在Python 2.6的site-packages ,并将其绑定到该版本。

The first thing to check is whether you can import mapnik in Python 2.6. 首先要检查的是您是否可以在Python 2.6中导入mapnik So run python from the terminal (not /usr/local/bin/python ). 因此,从终端(而不是/usr/local/bin/python )运行python If that works, then that will confirm what I've mentioned above. 如果可行,那么可以确认我上面提到的内容。

The quickest solution is to fix your $PATH environment variable to point to the correct version of python and then re-install mapnik. 最快的解决方案是修复$ PATH环境变量,使其指向正确的python版本,然后重新安装mapnik。

The easiest solution, I recommend that you use Homebrew to install Python. 最简单的解决方案,建议您使用Homebrew安装Python。 Homebrew is a package manager for OSX. Homebrew是OSX的软件包管理器。

To install Homebrew, in the terminal type: 要安装Homebrew,请在终端中输入:

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"

Then to install Python: 然后安装Python:

brew install python

Then to install mapnik; 然后安装mapnik;

brew install mapnik

If you use Homebrew, everything should be setup properly, automatically and in theory, there should be no version collisions. 如果您使用Homebrew,则应该正确,自动地进行所有设置,并且从理论上讲,应该没有版本冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM