Skip to content

Commit c126c32

Browse files
committed
Add Unix build notes
1 parent 9356a5b commit c126c32

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

mapscript/python/README.rst

+46-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Python MapScript for MapServer 7.2.1 README
22
===========================================
33

44
:Author: MapServer Team
5-
:Last Updated: 2018-10-12
5+
:Last Updated: 2018-11-28
66

77
Introduction
88
------------
@@ -51,8 +51,8 @@ running correctly.
5151
..
5252
py3 SWIG flag adds type annotations
5353
54-
Installation
55-
------------
54+
Installation on Windows
55+
-----------------------
5656

5757
To use mapscript you will need to add the MapServer binaries to your system path.
5858
On Windows you can use the following, replacing ``C:\MapServer\bin`` with the location of your MapServer binaries.
@@ -61,11 +61,11 @@ On Windows you can use the following, replacing ``C:\MapServer\bin`` with the lo
6161
6262
SET PATH=C:\MapServer\bin;%PATH%
6363
64-
Windows binary packages can be downloaded from `GIS Internals <https://www.gisinternals.com/stable.php>`.
64+
Windows binary packages can be downloaded from `GIS Internals <https://www.gisinternals.com/stable.php>`_.
6565
To ensure compatibility with the wheels, please use identical release packages, e.g. ``release-1911-x64-gdal-2-3-mapserver-7-2``
6666
for mapscript 7.2.
6767

68-
When using these packages the MapServer path will be similar to `C:\release-1911-x64-gdal-2-3-mapserver-7-2\bin`.
68+
When using these packages the MapServer path will be similar to ``C:\release-1911-x64-gdal-2-3-mapserver-7-2\bin``.
6969

7070
Prior to installing mapscript it is recommended to update pip to the latest version with the following command:
7171

@@ -106,6 +106,40 @@ If your version of mapscript does not match your version of MapServer you may in
106106
ImportError: DLL load failed: The specified module could not be found.
107107
ImportError: DLL load failed: The specified procedure could not be found.
108108
109+
Installation on Unix
110+
--------------------
111+
112+
For Unix users there are two approaches to installing mapscript. The first is to install the ``python-mapscript`` package using a package manager. For example on
113+
Ubuntu the following command can be used:
114+
115+
.. code-block:: bat
116+
117+
sudo apt-get install python-mapscript
118+
119+
The second approach is to build and install the Python mapscript module from source. Full details on compiling MapServer from source are detailed on the
120+
`Compiling on Unix <https://www.mapserver.org/installation/unix.html>`_ page. To make sure Python mapscript is built alongside MapServer the following flag needs to be set:
121+
122+
.. code-block:: bat
123+
124+
-DWITH_PYTHON=ON
125+
126+
To configure the path of the mapscript installation location ``-DCMAKE_INSTALL_PREFIX`` can be set, e.g.
127+
128+
.. code-block:: bat
129+
130+
sudo cmake .. -DCMAKE_INSTALL_PREFIX=/usr
131+
132+
When installing the `DESTDIR <https://cmake.org/cmake/help/latest/envvar/DESTDIR.html>`_ variable can be set (note ``DESTDIR`` is not used on Windows)
133+
to install mapscript to a non-default location. E.g.
134+
135+
.. code-block:: bat
136+
137+
make install DESTDIR=/tmp
138+
139+
In summary the ``install`` target runs the ``setup.py install`` command using custom paths (when set) similar to below:
140+
141+
python setup.py install --root=${DESTDIR} --prefix={CMAKE_INSTALL_PREFIX}
142+
109143
Quickstart
110144
----------
111145

@@ -118,19 +152,19 @@ To open an existing Mapfile:
118152
119153
>>> import mapscript
120154
>>> test_map = mapscript.mapObj(r"C:\Maps\mymap.map")
121-
>>> e = test_map.extent
155+
>>> extent = test_map.extent
122156
123157
Create a layer from a string:
124158

125159
.. code-block:: python
126160
127161
>>> import mapscript
128-
>>> lo = mapscript.fromstring("""LAYER NAME "test" TYPE POINT END""")
129-
>>> lo
162+
>>> layer = mapscript.fromstring("""LAYER NAME "test" TYPE POINT END""")
163+
>>> layer
130164
<mapscript.layerObj; proxy of C layerObj instance at ...>
131-
>>> lo.name
165+
>>> layer.name
132166
'test'
133-
>>> lo.type == mapscript.MS_LAYER_POINT
167+
>>> layer.type == mapscript.MS_LAYER_POINT
134168
True
135169
136170
Building the Mapscript Module
@@ -139,14 +173,14 @@ Building the Mapscript Module
139173
The mapscript module is built as part of the MapServer CMake build process. This is configured using the ``mapserver/mapscript/CMakeLists.txt`` file.
140174

141175
Before the switch to CMake MapServer mapscript was built using distutils and ``setup.py``. Now the ``setup.py.in`` file is used as a template that
142-
is filled with the MapServer version number and used to created wheel files for distribution.
176+
is filled with the MapServer version number and used to created wheel files for distribution, or install mapscript directly on the build machine.
143177

144178
The build process works as follows.
145179

146180
+ CMake runs SWIG. This uses the SWIG interface files to create a ``mapscriptPYTHON_wrap.c`` file,
147181
and a ``mapscript.py`` file containing the Python wrapper to the mapscript binary module.
148182
+ CMake then uses the appropriate compiler on the system to compile the ``mapscriptPYTHON_wrap.c`` file into a Python binary module -
149-
``_mapscript.pyd`` file on Windows, and a ``_mapscript.so`` file on Windows.
183+
``_mapscript.pyd`` file on Windows, and a ``_mapscript.so`` file on Unix.
150184

151185
``CMakeLists.txt`` is configured with a ``pythonmapscript-wheel`` target that copies all the required files to the output build folder where they are then packaged
152186
into a Python wheel. The wheel can be built using the following command:

0 commit comments

Comments
 (0)