Question

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. 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. 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. I'm on Mac OSX 10.6, 64bit.

$ 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?, 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. 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:

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

That didn't help either. My working directory is now Macintosh:bin home_directory$.

I also noticed an error at the end of the Python install:

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

This message re-appeared at the end of the mapnik install. Perhaps neither of these installed properly? When I do mapnik-config -v it says 2.2.0. When I do python --version, it says 2.7.5. When I look in /usr/local/bin I can see these files: mapnik-config, mapnik-speed-check. I do not see any mapnik files when I look in /usr/bin.

UPDATE 2: IT WORKED! 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). 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! 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!

Était-ce utile?

La solution 2

You are correct, you have Python versions clashing. Since you are on OSX and you haven't really used terminal before, it is not going to be one 'easy fix'. I recommend you read this book http://linuxcommand.org/tlcl.php, to understand how to use the command line properly. Note: even though it is for Linux, it is for the BASH shell, which is used by default in 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. 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.

The first thing to check is whether you can import mapnik in Python 2.6. So run python from the terminal (not /usr/local/bin/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.

The easiest solution, I recommend that you use Homebrew to install Python. Homebrew is a package manager for OSX.

To install Homebrew, in the terminal type:

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

Then to install Python:

brew install python

Then to install mapnik;

brew install mapnik

If you use Homebrew, everything should be setup properly, automatically and in theory, there should be no version collisions.

Autres conseils

Even after brew install, you will have to manually export the bindings like this

export PYTHONPATH="/usr/local/lib/python2.7/site-packages"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top