0

I am on a django project where I want to use the python implementation of the mapserver mapscript library. I was able to install mapserver and python-mapscript from source.

However, due to the project setup I am forced to run django in a virtualenv that does not allow site-packages in my virtual environment.

Since mapscript is installed as a global site-package my django app can't see the mapscript installation. When I try to install mapscript through pip install mapscript I get an error 'mapserver.h' file not found.

How can I install python-mapscript in my virtual environment?

I thought of copying the installed egg into my virtual environment, but I am not sure if that is possible.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
yellowcap
  • 3,013
  • 22
  • 36
  • Related: https://github.com/mapserver/mapserver/issues/4267 – Chad Cooper Jan 17 '14 at 14:04
  • You can't install site-packages in your virtualenv? That's the whole point of using a virtualenv. – Chad Cooper Jan 17 '14 at 14:07
  • I am not trying to install the site-package per se in the virtualenv. I just wanted to point out that my installation works fine outside virtualenv, but I don't know how do an installation within it. – yellowcap Jan 17 '14 at 16:12
  • Ohhh. So when you are doing pip install mapscript are doing it from within the activated virtualenv (source bin/activate) and getting the error that mapserver.h is not found? – Chad Cooper Jan 17 '14 at 18:34
  • Yes that's exactly it, outside the virtualenv I was able to install mapscript from source, but in the virtualenv I dont konw how to do that and pip does throw that error. – yellowcap Jan 18 '14 at 13:09
  • Related: http://gis.stackexchange.com/questions/6360/ – yellowcap Sep 04 '14 at 12:58

1 Answers1

5

I just faced the same problem and solved it by copy the mapscript.py and _mapscript.so into my virtual env.

cd venv/lib/python2.7/site-packages
cp /usr/lib/python2.7/dist-packages/_mapscript.so .
cp /usr/lib/python2.7/dist-packages/mapscript.py .

At least the following script in a python web-app worked fine, based on the mapserver demo files I got here.

...
import mapscript
map = mapscript.mapObj(mapfile_path + "itasca.map")
img = map.draw()
img.save("/var/www/img/tmp/mapscript_test_itasca.png")
...

This is just a test script, which proved that the mapfile is correctly read and the picture is created.

I you are not allowed to copy, you may try your luck with pip install again by adding the include paths:

CPPFLAGS="-I/usr/include/mapserver -I/usr/include/gdal" pip install mapscript

I needed the packages libmapserver-dev, libgd-dev, libgdal-dev and libproj-dev installed to get the compiling running to start and ran into many errors. The log showed:

Using version 5.6.3.0 (newest of versions: 5.6.3.0, 5.4.2.1, 5.02.2.33)

While Mapserver 6.4 is installed on my system (and 7.0 just came out), there seems to by a compatibility issue. According to PyPi the most recept mapscript pip package is version 5.6 from 2010.

I guess you can't install it via pip unless you use mapserver 5.6 or older.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Wenzel
  • 66
  • 1
  • 2