Streamlit Cloud部署应用遇ImportError:缺失libXrender.so.1文件
解决Streamlit部署时rdkit.Chem.Draw导入失败(libXrender.so.1缺失)的问题
问题重现
本地Windows系统PyCharm中代码可正常运行,但上传至GitHub通过Streamlit部署时出现异常,导入rdkit.Chem.Draw模块触发ImportError,提示找不到libXrender.so.1文件。
错误日志
Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False. 2023-02-24 14:13:19.778 Uncaught app exception Traceback (most recent call last): File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 564, in _run_script exec(code, module.__dict__) File "/app/cug-drug-side-effects-prediction/App.py", line 19, in from rdkit.Chem import Draw File "/home/appuser/venv/lib/python3.9/site-packages/rdkit/Chem/Draw/__init__.py", line 21, in from rdkit.Chem.Draw import rdMolDraw2D ImportError: libXrender.so.1: cannot open shared object file: No such file or directory
当前requirements.txt内容
torch==1.13.0 matplotlib==3.5.2 translate==3.6.1 numpy==1.21.6 pandas==1.3.5 streamlit==1.15.1 plotly==5.11.0 scipy==1.7.3 networkx==2.6.3 rdkit==2022.9.2 requests==2.28.1 Pillow==9.4.0 scikit_learn==1.2.1 torch_geometric==2.1.0.post1 -f https://data.pyg.org/whl/torch-1.13.0+cu116.html torch-sparse -f https://data.pyg.org/whl/to
解决步骤
问题根源是Streamlit部署使用的Linux环境缺少rdkit绘图模块依赖的X11系统库,libXrender.so.1属于这类依赖,需通过系统包管理器安装:
- 在项目根目录创建packages.txt文件
- 将以下系统依赖写入文件:
libxrender1 libxext6 libsm6 libice6
这些包是rdkit绘图功能必需的图形基础库,覆盖了libXrender.so.1及关联依赖。
- 将
packages.txt和代码一起上传至GitHub,Streamlit Cloud会自动读取该文件并安装指定的系统包,重新部署即可解决导入错误。
内容的提问来源于stack exchange,提问作者cuger
相关产品推荐
相关产品推荐

