I have a dockerfile in which I am trying to build a container with my required python modules from.
See my dockerfile below to understand how and what modules I am trying to install:
FROM ubuntu:bionic
ENV ROOTDIR /usr/local/
ENV GDAL_VERSION 2.4.1
ENV OPENJPEG_VERSION 2.3.0
ENV CURL_CA_BUNDLE /etc/ssl/certs/ca-certificates.crt
# Load assets
WORKDIR $ROOTDIR/
ADD http://download.osgeo.org/gdal/${GDAL_VERSION}/gdal-${GDAL_VERSION}.tar.gz $ROOTDIR/src/
ADD https://github.com/uclouvain/openjpeg/archive/v${OPENJPEG_VERSION}.tar.gz $ROOTDIR/src/openjpeg-${OPENJPEG_VERSION}.tar.gz
# Install basic dependencies
RUN apt-get update -y && apt-get install -y
software-properties-common
build-essential
python-dev
python3-dev
python-numpy
python3-numpy
python3-pyproj
libspatialite-dev
sqlite3
libpq-dev
libcurl4-gnutls-dev
libproj-dev
libxml2-dev
libgeos-dev
libnetcdf-dev
libpoppler-dev
libspatialite-dev
libhdf4-alt-dev
libhdf5-serial-dev
bash-completion
cython
cmake
# Compile and install OpenJPEG
RUN cd src && tar -xvf openjpeg-${OPENJPEG_VERSION}.tar.gz && cd openjpeg-${OPENJPEG_VERSION}/
&& mkdir build && cd build
&& cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$ROOTDIR
&& make && make install && make clean
&& cd $ROOTDIR && rm -Rf src/openjpeg*
# Compile and install GDAL
RUN cd src && tar -xvf gdal-${GDAL_VERSION}.tar.gz && cd gdal-${GDAL_VERSION}
&& ./configure --with-python --with-spatialite --with-pg --with-curl --with-openjpeg
&& make -j $(nproc) && make install && ldconfig
&& apt-get update -y
&& cd $ROOTDIR && cd src/gdal-${GDAL_VERSION}/swig/python
&& python3 setup.py build
&& python3 setup.py install
&& apt-get remove -y --purge build-essential
python-dev
python3-dev
&& cd $ROOTDIR && rm -Rf src/gdal*
# install Vim
RUN apt-get -y install vim
# Install Pip3 and required python modules
RUN apt-get -y install python3-pip
RUN pip3 install rasterio &&
pip3 install rdp &&
pip3 install gdal2tiles&&
pip3 install awscli &&
pip3 install pandas &&
pip3 install boto3 &&
pip3 install requests &&
pip3 install shapely &&
pip3 install geopandas &&
pip3 install math
However, it seems to get as far as the geopandas module and then I hit this error:
Collecting pyproj>=2.2.0 (from geopandas)
Downloading https://files.pythonhosted.org/packages/2c/12/7a8cca32506747c05ffd5c6ba556cf8435754af0939906cbcc7fa5802ea3/pyproj-3.0.1.tar.gz (168kB)
Complete output from command python setup.py egg_info:
ERROR: Cython.Build.cythonize not found. Cython is required to build pyproj.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-vtfufrfs/pyproj/
Has anyone any ideas on how to overcome this?
2
Answers
Your Python3 environment is missing the Cython package. Add the line
pip3 install cython
before thepip3 install geopandas
line.You will need to upgrade your pip version as well.
And it is more convenient to use pip directly from the Python3 interpreter rather than the pip3 wrapper. So I will go to refactor your last
RUN
block like so:Try this way in your dockerfile