Ubuntu18.04/20.04/22.04にmapnikインストール

## Ubuntu 18.04 (Python 3.6)

python3-mapnikの動作問題無し

```Dockerfile
FROM ubuntu:18.04

RUN apt update
RUN apt upgrade -y
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt update && apt install -y \
    python3.6 \
    python3.6-dev \
    python-pip \
    libgdal-dev \
    gdal-bin \
    libmapnik-dev \
    python3-mapnik

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.6 10

RUN update-alternatives --set python /usr/bin/python3.6
```

```sh
[CORP\sano2@a-2jeos6wr3a190 test2]$ docker run --name test6 -it example2:latest sh
# python
Python 3.6.9 (default, Mar 10 2023, 16:46:00) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mapnik
>>> 
```

## Ubuntu 18.04 (Python 3.7)

python3-mapnik動作おかしい

```Dockerfile
FROM ubuntu:18.04

RUN apt update
RUN apt upgrade -y
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt update && apt install -y \
    python3.7 \
    python3.7-dev \
    python-pip \
    libgdal-dev \
    gdal-bin \
    libmapnik-dev \
    python3-mapnik

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.7 10

RUN update-alternatives --set python /usr/bin/python3.7
```

```sh
[CORP\sano2@a-2jeos6wr3a190 test2]$ docker run --name test6 -it example2:latest sh
# python
Python 3.7.5 (default, Dec  9 2021, 17:04:37) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mapnik
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/mapnik/__init__.py", line 74, in <module>
    from ._mapnik import *
ModuleNotFoundError: No module named 'mapnik._mapnik'
>>> 
```

## Ubuntu 20.04 (Python 3.8)

python3-mapnikの動作問題無し

```Dockerfile
FROM ubuntu:20.04

RUN apt update
RUN apt upgrade -y
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt update && apt install -y \
    python3.8 \
    python3.8-dev \
    python3-pip \
    libgdal-dev \
    gdal-bin \
    libmapnik3.0 \
    python3-mapnik

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.8 10

RUN update-alternatives --set python /usr/bin/python3.8
```

```sh
[CORP\sano2@a-2jeos6wr3a190 test2]$ docker run --name test6 -it example2:latest sh
# python
Python 3.8.10 (default, May 26 2023, 14:05:08) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mapnik
>>> 
```

## Ubuntu 20.04 (Python 3.9)

python3-mapnikの動作おかしい

```Dockerfile
FROM ubuntu:20.04

RUN apt update
RUN apt upgrade -y
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt update && apt install -y \
    python3.9 \
    python3.9-dev \
    python3-pip \
    libgdal-dev \
    gdal-bin \
    libmapnik3.0 \
    python3-mapnik

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 10

RUN update-alternatives --set python /usr/bin/python3.9
```

```sh
[CORP\sano2@a-2jeos6wr3a190 test2]$ docker run --name test6 -it example2:latest sh
# python
Python 3.9.18 (main, Aug 25 2023, 13:20:04) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mapnik
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/mapnik/__init__.py", line 74, in <module>
    from ._mapnik import *
ModuleNotFoundError: No module named 'mapnik._mapnik'
>>> 

```

## Ubuntu 22.10 (Python 3.9)

python3-mapnikの動作おかしい

Ubuntu 22.04にlibmapnik3.0は無い
https://packages.ubuntu.com/search?keywords=mapnik&searchon=names


```Dockerfile
FROM docker.osgeo.org/geoserver:2.23.1

RUN apt update
RUN apt upgrade -y
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt update && apt install -y \
    python3.9 \
    python3.9-dev \
    python3-pip \
    libgdal-dev \
    gdal-bin \
    libmapnik3.1 \
    python3-mapnik

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 10

RUN update-alternatives --set python /usr/bin/python3.9
```

```sh
[CORP\sano2@a-2jeos6wr3a190 ~]$ docker exec -it 19313b17516b sh
# python
Python 3.9.18 (main, Aug 25 2023, 13:20:14) 
[GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mapnik
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/mapnik/__init__.py", line 74, in <module>
    from ._mapnik import *
ModuleNotFoundError: No module named 'mapnik._mapnik'
```

## Ubuntu 22.10 (Python 2.7)

mapnikの動作問題無し

Ubuntu 22.04にpython-mapnikは無かったのでpipでinstall
https://packages.ubuntu.com/search?keywords=mapnik&searchon=names


```Dockerfile: Dockerfile
FROM docker.osgeo.org/geoserver:2.23.1

RUN apt update
RUN apt upgrade -y
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt update && apt install -y \
    python2.7 \
    python2.7-dev \
    python-pip \
    libgdal-dev \
    gdal-bin

RUN update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10

RUN update-alternatives --set python /usr/bin/python2.7

RUN  mkdir /app
WORKDIR /app
COPY requirements.txt /app/
RUN python -m pip install -r requirements.txt

RUN python -V
RUN python -m pip freeze
```

```requirements.txt
numpy==1.16.6
gdal==3.2.3
scikit-learn==0.20.4
shapely==1.7.1
pyproj==2.2.2
fiona==1.8.21
mapnik==0.1
```

```sh
# python
Python 2.7.18 (default, Jul  1 2022, 10:30:50) 
[GCC 11.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mapnik
>>> 
```

## 参考URL

[mapnik](https://github.com/mapnik/mapnik)
[python-mapnik](https://github.com/mapnik/python-mapnik)
[docker-mapnik3](https://github.com/jawg/docker-mapnik3)
[build_mapnik_ubuntu_22](https://gist.github.com/benboughton1/e38ba6d53e46e668ffe21b1cd478397f)