Dockerfile 努力安装 Python Geopandas 模块
Dockerfile struggling to install Python Geopandas module
我有一个 dockerfile,我试图在其中使用我所需的 python 模块构建一个容器。
查看下面的 dockerfile 以了解我尝试安装的模块和模块的安装方式:
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
然而,它似乎到达了 geopandas 模块,然后我遇到了这个错误:
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/
有没有人知道如何克服这个问题?
您的 Python3 环境缺少 Cython 包。在 pip3 install geopandas
行之前添加行 pip3 install cython
。
您还需要升级 pip 版本。
直接从 Python3 解释器而不是 pip3 包装器使用 pip 更方便。所以我将像这样重构你的最后一个 RUN
块:
RUN \
python3 -m pip install --upgrade pip \
&& python3 -m pip install \
cython \
rasterio \
rdp \
gdal2tiles \
awscli \
pandas \
boto3 \
requests \
shapely \
geopandas
在你的 dockerfile 中尝试这种方式
RUN wget http://download.osgeo.org/libspatialindex/spatialindex-src-1.8.5.tar.gz && \
tar -xvzf spatialindex-src-1.8.5.tar.gz && \
cd spatialindex-src-1.8.5 && \
./configure && \
make && \
make install && \
cd - && \
rm -rf spatialindex-src-1.8.5* && \
ldconfig
### Install rtree and geopandas
RUN pip install rtree geopandas
我有一个 dockerfile,我试图在其中使用我所需的 python 模块构建一个容器。
查看下面的 dockerfile 以了解我尝试安装的模块和模块的安装方式:
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
然而,它似乎到达了 geopandas 模块,然后我遇到了这个错误:
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/
有没有人知道如何克服这个问题?
您的 Python3 环境缺少 Cython 包。在 pip3 install geopandas
行之前添加行 pip3 install cython
。
您还需要升级 pip 版本。
直接从 Python3 解释器而不是 pip3 包装器使用 pip 更方便。所以我将像这样重构你的最后一个 RUN
块:
RUN \
python3 -m pip install --upgrade pip \
&& python3 -m pip install \
cython \
rasterio \
rdp \
gdal2tiles \
awscli \
pandas \
boto3 \
requests \
shapely \
geopandas
在你的 dockerfile 中尝试这种方式
RUN wget http://download.osgeo.org/libspatialindex/spatialindex-src-1.8.5.tar.gz && \
tar -xvzf spatialindex-src-1.8.5.tar.gz && \
cd spatialindex-src-1.8.5 && \
./configure && \
make && \
make install && \
cd - && \
rm -rf spatialindex-src-1.8.5* && \
ldconfig
### Install rtree and geopandas
RUN pip install rtree geopandas