ImportError:OpenShift在线平台上的libXrender.so.1

问题描述

我当时在OpenShift Online Platform上使用streamlit,PyTorch和OpenCV构建了一个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窗口的依赖项,在服务器(无头)环境中通常不需要这些窗口。