我有一個 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/
有沒有人知道如何克服這個問題?
uj5u.com熱心網友回復:
您的 Python3 環境缺少 Cython 包。pip3 install cython在行前添加pip3 install geopandas行。
您還需要升級您的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
uj5u.com熱心網友回復:
在您的 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/487029.html
