ubuntu 无法为cartopy linux安装Proj 8.0.0

tzxcd3kk  于 2023-08-03  发布在  Linux
关注(0)|答案(3)|浏览(183)

我正在尝试在Ubuntu上安装Cartopy,需要为Cartopy安装proj v8.0.0二进制文件。但是,当我尝试apt-get install proj-bin时,我只能得到proj v6.3.1。如何为cartopy安装最新的(或至少v8.0.0)项目?

hyrbngr7

hyrbngr71#

我在这里回答我自己的问题,部分是为了帮助其他人解决这个问题,部分是为了自己存档,这样我就知道如果再次遇到这个问题如何解决。我花了相当长的一段时间试图弄清楚,并写了详细的说明,所以请参阅下面:

安装cartopy是一个巨大的痛苦,我发现使用conda是一个非常糟糕的主意(对我来说,它已经多次将自己和Python沿着砖化)

此安装适用于Linux。

步骤0.更新apt:

apt update

字符串

第一步安装GEOS:

运行以下命令安装GEOS:

apt-get install libgeos-dev


如果这样做不成功,请使用以下命令安装所有文件:

apt-get install libgeos-dev libgeos++-dev libgeos-3.8.0 libgeos-c1v5 libgeos-doc

第二步安装proj依赖:

  • 安装cmake:
apt install cmake

  • 安装sqlite3:
apt install sqlite3

  • 安装curl开发包:
apt install curl && apt-get install libcurl4-openssl-dev

第三步安装Proj

尝试apt-get以防万一:

不幸的是,cartopy至少需要proj v8.0.0,但是如果使用apt安装proj,则只能安装proj v6.3.1
仅供参考,以防发生任何更改,这是从apt安装proj的命令:

apt-get install proj-bin


我很确定这就是你所需要的,但如果不是,这个命令将安装其余的proj文件:

apt-get install proj-bin libproj-dev proj-data


要删除上述安装,请运行:

apt-get remove proj-bin


或:

apt-get remove proj-bin libproj-dev proj-data

从源构建项目

因此,如果上述命令不起作用(截至2022年4月8日,它不起作用),请按照以下说明从源代码安装proj:

  • 转到您的安装文件夹并下载proj-9.0.0(或任何带有proj-x.x.x.tar.gz的版本):
wget https://download.osgeo.org/proj/proj-9.0.0.tar.gz

  • 解压缩tar.gz文件:
tar -xf proj-9.0.0.tar.gz

  • cd放入文件夹:
cd proj-9.0.0

  • 创建一个build文件夹并将cd放入其中:
mkdir build && cd build

  • 运行(这可能需要一段时间):
cmake ..
cmake --build .
cmake --build . --target install

  • 运行以确保所有内容都正确安装:
ctest


test命令在我的一个测试(19 - nkg)上失败,但其他方面都很好。
您应该在./bin目录中找到所需的文件
最后:

  • 将二进制文件移动到/bin目录:
cp ./bin/* /bin

  • 根据Justino,您可能还需要移动库:
cp ./lib/* /lib


完成这一切之后,你终于可以用pip安装cartopy了:

pip install cartopy


做完这些之后,我的cartopy仍然不起作用。我回家工作,这一个星期,回来,突然它的工作,所以也许尝试重新启动

brgchamk

brgchamk2#

应该手动复制库sudo cp ./lib/* /lib这对我很有效

qc6wkl3g

qc6wkl3g3#

下面是一个MultistageDockerfile,我把它放在一起,用于处理大气数据和机器学习。

# syntax=docker/dockerfile:1

# Description:
# Multistage Dockerfile for working with the SEVIR dataset and other atmospheric
# data formats for analysis, processing, and Machine Learning.

# Example:
# - docker build -t $USER/sevir . 
# - docker run -it -p 8888:8888 --gpus all --volume $PATH_TO_SEVIR:/home/vscode $USER/sevir

# TODD:
# install ffmpeg for video processing needed for matplotlib animations
# sudo apt install ffmpeg    

FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04 AS base
USER root

WORKDIR /
SHELL ["/bin/bash","-c"]
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && apt-get install -y --no-install-recommends \
    python3.10 \
    python3.10-venv \
    libgeos3.10.2 \
    libgdal30 \
    && rm -rf /var/lib/apt/lists/* \
    && python3.10 -m venv /opt/venv

ENV PATH="/opt/venv/bin:$PATH"
USER 1001

# =====================================================================================================================
# Compiler Stage; this will be omitted from the final image
# =====================================================================================================================
FROM base AS compiler
USER root

WORKDIR /
SHELL ["/bin/bash","-c"]
ENV DEBIAN_FRONTEND=noninteractive
# hadolint ignore=DL3008
RUN apt-get update -y \
    && apt-get install -y --no-install-recommends \
    wget \
    gcc   \
    g++    \
    cmake   \
    gfortran \
    python3.10-dev \
    build-essential \
    # see: https://github.com/OSGeo/PROJ/blob/master/Dockerfile
    zlib1g-dev libsqlite3-dev sqlite3 libcurl4-gnutls-dev libtiff5-dev libsqlite3-0 libtiff5 \
    libgdal-dev libatlas-base-dev libhdf5-serial-dev \
    && rm -rf /var/lib/apt/lists/*

USER 1001

# =====================================================================================================================
# EcCodes is a library for decoding and encoding grib files.
# =====================================================================================================================
FROM compiler AS eccodes
USER root
ARG ECCODES="eccodes-2.24.2-Source" 
ARG ECCODES_DIR="/usr/include/eccodes"

WORKDIR /tmp
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN wget -c --progress=dot:giga \
    https://confluence.ecmwf.int/download/attachments/45757960/${ECCODES}.tar.gz  -O - | tar -xz -C . --strip-component=1 

WORKDIR /tmp/build
SHELL ["/bin/bash","-c"]
RUN cmake -DCMAKE_INSTALL_PREFIX="${ECCODES_DIR}" -DENABLE_PNG=ON .. \
    && make -j"$(nproc)" \
    && make install

USER 1001

# =====================================================================================================================
# PROJ is a library for coordinate transformations, and is a requirement for cartopy.
# =====================================================================================================================
FROM compiler AS proj
USER root

WORKDIR /proj
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN wget -c --progress=dot:giga \
    https://github.com/OSGeo/PROJ/archive/refs/tags/9.0.1.tar.gz  -O - | tar -xz -C . --strip-component=1 

WORKDIR /proj/build
SHELL ["/bin/bash","-c"]
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF \
    && make -j"$(nproc)" \
    && make install

USER 1001

# =====================================================================================================================
# Cartopy is a python library for plotting data on maps.
# =====================================================================================================================
FROM proj AS cartopy
USER root

SHELL ["/bin/bash","-c"]
ENV DEBIAN_FRONTEND=noninteractive
# hadolint ignore=DL3008
RUN apt-get update -y \
    && apt-get install -y --no-install-recommends \
    python3.10-dev \
    && rm -rf /var/lib/apt/lists/*
# hadolint ignore=DL3013
RUN python3.10 -m pip install --upgrade pip --no-cache-dir && python3.10 -m pip install --no-cache-dir \
    Cartopy==0.21.1 \
    matplotlib==3.7.2

USER 1001

# =====================================================================================================================
# Final Image
# =====================================================================================================================
FROM base AS lunch-box
USER root
ARG USERNAME=vscode 
ARG USER_UID=1000
ARG USER_GID=$USER_UID

WORKDIR /tmp/sevir
SHELL ["/bin/bash","-c"]
# hadolint ignore=DL3008
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
    && chown -R $USER_UID:$USER_GID /opt/venv

ENV ECCODES_DIR=/usr/include/eccodes
COPY --from=eccodes --chown=$USER_UID:$USER_GID $ECCODES_DIR $ECCODES_DIR
COPY --from=cartopy --chown=$USER_UID:$USER_GID /opt/venv /opt/venv
# - install requirements that arn't in the requirements.txt and torch for caching
RUN python3.10 -m pip install --no-cache-dir \
    torch==2.0.1 \
    cfgrib==0.9.10.4 \
    notebook==6.5.4 \
    eccodes==1.6.0 
# - install the package and dependencies
COPY src/ src/
COPY setup.py setup.py
COPY pyproject.toml pyproject.toml
RUN python3.10 -m pip install . --no-cache-dir && rm -rf /tmp/*

USER $USERNAME
ARG HOME=/home/$USERNAME
WORKDIR $HOME
COPY --chown=$USER_UID:$USER_GID notebooks/ examples/
VOLUME $HOME/sevir-volume
ENV PATH_TO_SEVIR=$HOME/sevir-volume/sevir

CMD [ "jupyter", "notebook", "--ip=0.0.0.0", "--NotebookApp.token=''", "--NotebookApp.password=''", "--no-browser" ]

字符串

相关问题