ImportError: libXrender.so.1 on OpenShift Online Plaform

ImportError: libXrender.so.1 on OpenShift Online Plaform

我正在使用 streamlit、PyTorch 和 OpenCV 在 OpenShift 在线平台上构建一个 Web 应用程序。在开始执行 Python 脚本之前一直 运行 很好:

Traceback (most recent call last):
File "app.py", line 11, in <module>
  import cv2
File "/opt/app-root/lib/python3.6/site-packages/cv2/__init__.py", line 3, in <module>
  from .cv2 import *
ImportError: libXrender.so.1: cannot open shared object file: No such file or directory

我知道解决方法就是安装缺少的库“libXrender”。但问题是我找不到实现它的方法(我已经尝试 docker)。那么可以在 OpenShift Online Platform 上打开终端控制台吗?

PS: 我正在使用 OpenShift 的启动包,以下是我的 Dockerfile:

FROM pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime
RUN pip install virtualenv
# only needed when using OpenShift
RUN apt-get install libxrender1
ENV VIRTUAL_ENV=/venv
RUN virtualenv venv -p python3
ENV PATH="VIRTUAL_ENV/bin:$PATH"

WORKDIR /app
ADD . /app

# Install dependencies
RUN apt update
RUN apt-get install -y libglib2.0-0 libsm6 libxrender1 libxext6
RUN pip install -r requirements.txt

# copying all files over
COPY . /app

# Expose port 
ENV PORT 8501

# cmd to launch app when container is run
CMD streamlit run app.py

# streamlit-specific commands for config
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
RUN mkdir -p /root/.streamlit
RUN bash -c 'echo -e "\
[general]\n\
email = \"\"\n\
" > /root/.streamlit/credentials.toml'

RUN bash -c 'echo -e "\
[server]\n\
enableCORS = false\n\
" > /root/.streamlit/config.toml'

在不知道您的 requirements.txt 中有什么的情况下,我相信您可以通过安装 opencv-python 的无头版本(服务器环境)即 opencv-python-headless 来缓解这个问题。然后你很可能也可以删除 libsm6 libxrender1 libxext6。这些是用于显示 GUI windows 的依赖项,在服务器(无头)环境中通常不需要。