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

2024-10-02 22:23:50 发布

您现在位置:Python中文网/ 问答频道 /正文

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

PyFMI的问题在于它不适用于ARMv8体系结构。我尝试在docker中使用miniconda作为基本映像MiniForge(ARMv8不提供miniconda),但即使使用该映像,也无法使用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中直接安装PyFMI for ARMv8体系结构,效果会更好

谢谢


Tags: installrundevgitforusrlocalapt