简体   繁体   English

Dockerfile 努力安装 Python Geopandas 模块

[英]Dockerfile struggling to install Python Geopandas module

I have a dockerfile in which I am trying to build a container with my required python modules from.我有一个 dockerfile,我试图在其中使用所需的 python 模块构建一个容器。

See my dockerfile below to understand how and what modules I am trying to install:请参阅下面的 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 

However, it seems to get as far as the geopandas module and then I hit this error:但是,它似乎已经到了 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/

Has anyone any ideas on how to overcome this?有没有人知道如何克服这个问题?

Your Python3 environment is missing the Cython package.您的 Python3 环境缺少 Cython 包。 Add the line pip3 install cython before the pip3 install geopandas line.pip3 install geopandas行之前添加行pip3 install cython

You will need to upgrade your pip version as well.您还需要升级您的pip版本。 And it is more convenient to use pip directly from the Python3 interpreter rather than the pip3 wrapper.并且直接从 Python3 解释器而不是pip3包装器使用pip更方便。 So I will go to refactor your last RUN block like so:因此,我将像这样重构您的最后一个RUN块:

RUN \
   python3 -m pip install --upgrade pip \
   && python3 -m pip install \
        cython \
        rasterio \
        rdp \
        gdal2tiles \
        awscli \
        pandas \
        boto3 \
        requests \
        shapely \
        geopandas

Try this way in your dockerfile在您的 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM