微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 ARMv8 架构中安装最新版本的 PyFMI 以在 Raspberry Pi 4B 上的 docker 容器中运行

如何解决如何在 ARMv8 架构中安装最新版本的 PyFMI 以在 Raspberry Pi 4B 上的 docker 容器中运行

我尝试使用 docker 容器在 RaspBerry Pi 4B 上安装 PyFMI 已经有一段时间了。我设法以某种方式成功。但是,仍然缺少更新日晷。如果有人可以帮助找到更新它的解决方法,我将不胜感激。目前,我将发布我所做的。它可能对其他人有帮助(即使它不是一个完美的解决方案)。

PyFMI 的问题在于它不适用于 ARMv8 架构。我尝试在 docker 中使用 mini-forge 作为基础映像(miniconda 不适用于 ARMv8),但即使使用该映像也无法使用 conda 命令(conda install -c conda-forge pyfmi)进行直接安装。所以,我需要从源代码编译所有 PyFMI。我用这篇文章作为帮助:PyFMI in Python 3 environment in Ubuntu 18.04

遵循代码

FROM  condaforge/miniforge3 AS compile-image
ENV TZ=America/Montreal
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN apt-get -y update && apt-get -y upgrade \
        && apt-get install -y libblas-dev \
        liblapack-dev           \
        libopenblas-dev         \
        python3-dev             \
        libatlas-base-dev       \
        libblas-dev             \
        gcc                     \       
        g++                     \
        build-essential         \         
        zlib1g-dev              \
        gfortran                \
        autoconf                \       
        automake                \       
        bzip2                   \       
        dpkg-dev                \       
        file                    \
        cmake                   \
        git                     \
        # Additional requirements for EnergyPlustoFMU
        ca-certificates         \
        libxslt-dev             \
        swig                    \
        libssl-dev              \
        tree                    \
        libx11-6                \
        curl                    \
        tar 

RUN pip install numpy
RUN pip install Cython
RUN pip install pandas
RUN pip install scipy
# RUN conda install -c conda-forge pyfmi # miniforge is not able to find the package.

# Manually compile all needed packages for PyFMI
# Source: https://stackoverflow.com/questions/59582257/pyfmi-in-python-3-environment-in-ubuntu-18-04 

# Add FMI Library  
workdir /
RUN mkdir ./FMILibraryInstaller
RUN git clone https://github.com/modelon-community/fmi-library.git FMILibraryInstaller
RUN ls -lha
workdir /FMILibraryInstaller
RUN mkdir ./buildcmake
workdir /FMILibraryInstaller/buildcmake
# Variable DFMILIB_INSTALL_PREFIX defines the directory of installation
RUN cmake -DFMILIB_INSTALL_PREFIX=/usr/local/FMILibrary /FMILibraryInstaller/
RUN make install 
# Create enviroment variable for PyFMI installation (required for posterior installation of PyFMI).
ENV FMIL_HOME=/usr/local/FMILibrary

# Add sundials Library 
workdir /
RUN mkdir /SundialsInstaller
workdir /SundialsInstaller
RUN wget https://github.com/LLNL/sundials/archive/refs/tags/v4.1.0.tar.gz 
RUN mkdir buildtar
workdir /SundialsInstaller/buildtar
RUN tar -xf /SundialsInstaller/v4.1.0.tar.gz
RUN ls -lha
workdir /SundialsInstaller/buildtar/sundials-4.1.0
RUN mkdir buildcmake
workdir /SundialsInstaller/buildtar/sundials-4.1.0/buildcmake
RUN cmake -DCMAKE_INSTALL_PREFIX=/usr/local/Sundials /SundialsInstaller/buildtar/sundials-4.1.0
RUN make install

# Add lapack Library 
workdir /
RUN mkdir /LapackInstaller
RUN git clone https://github.com/Reference-LAPACK/lapack-release.git LapackInstaller
RUN ls -lha
workdir /LapackInstaller
RUN mkdir ./buildcmake
workdir /LapackInstaller/buildcmake
RUN cmake -DCMAKE_INSTALL_PREFIX=/usr/local/Lapack /LapackInstaller
RUN make install

# Add assimulo Library 
workdir /
RUN mkdir /AssimuloInstaller
RUN git clone https://github.com/modelon-community/Assimulo.git AssimuloInstaller 
workdir /AssimuloInstaller
RUN ls -lha
RUN python setup.py install --sundials-home=/usr/local/Sundials 
# --blas-home=/usr/local/Lapack/lib --lapack-home=/usr/local/Lapack

# Add PyFMI
# FMIL_HOME is an ambient variable. Needs to be exposed so it can be found for the PyFMI installer.  
RUN export FMIL_HOME=/FMILibraryInstaller/buildcmake
workdir /
RUN git clone https://github.com/modelon-community/PyFMI.git PyFMIInstaller
workdir /PyFMIInstaller
RUN ls -lha
RUN python setup.py install --fmil-home=/usr/local/FMILibrary

需要注意的几件事:

  • 定义环境变量 TZ 是为了避免在 Ubuntu 安装中手动输入其值。
  • 使用 FMI 库的路径创建环境变量。
  • 最新版本的日晷与最新版本的 Assimulo 不兼容。 Assimulo 安装需要一个名为“sundials_sparse.h”的文件,该文件在 Sundials 的最新版本中不存在。这就是为什么要安装 4.1 版。
  • 安装 Assimulo 需要指定日晷、blas 和 lapack 的路径。但是,如果不直接指定根目录,安装就可以正常完成。
  • PyFMI 需要指定 FMI 库的路径和路径的环境变量。

如果有人找到如何安装最新版本的日晷,我将不胜感激。或者,更好的是,如果有人可以在 conda-forge 中为 ARMv8 架构创建直接安装 PyFMI 会更好。

谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。