RDKit and Streamlit

Hi there!

I am using RDKit in my application, which runs fine locally.

import mols2grid
import pandas as pd
import streamlit as st
import streamlit.components.v1 as components
from rdkit import Chem
from rdkit.Chem.Descriptors import ExactMolWt

However, when I try to deploy the app, all the dependencies are processed, but I get the error:
Traceback (most recent call last):
File “/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py”, line 349, in _run_script
exec(code, module.dict)
File “/app/cdd/original-app.py”, line 5, in
import mols2grid
File “/home/appuser/venv/lib/python3.7/site-packages/mols2grid/init.py”, line 1, in
from .molgrid import MolGrid
File “/home/appuser/venv/lib/python3.7/site-packages/mols2grid/molgrid.py”, line 9, in
from rdkit import Chem
ModuleNotFoundError: No module named ‘rdkit’

I’m not sure if I need to include rdkit in the requirements.txt file even though I’m not installing it. I used the rdkit environment.

Hope you can help!

Hi @sgehl, welcome to the Streamlit community!! :clap: :partying_face:

Could you clarify what you mean by:

even though I’m not installing it. I used the rdkit environment.

Any Python packages you import in your app that are not distributed with a standard Python installation should be included in your requirements file.

To fix the ModuleNotFoundError: No module named ‘rdkit’ error, you need to include rdkit-pypi in your requirements.txt file. :slight_smile:

Happy Streamlit’ing! :balloon:
Snehan

Thank you! The problem is I’m not importing RDKit, I just use its virtual environment because whenever I try to install RDKit it shows an error:
ERROR: Could not find a version that satisfies the requirement rdkit-pypi (from versions: none)
ERROR: No matching distribution found for rdkit-pypi

I added the rdkit-pypi==2021.3.3 in the requirements.txt file, but it is still showing an error:

Traceback (most recent call last):

** File “/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py”, line 349, in _run_script**

** exec(code, module.dict)**

** File “/app/cdd/original-app.py”, line 5, in **

** import mols2grid**

** File “/home/appuser/venv/lib/python3.7/site-packages/mols2grid/init.py”, line 1, in **

** from .molgrid import MolGrid**

** File “/home/appuser/venv/lib/python3.7/site-packages/mols2grid/molgrid.py”, line 10, in **

** from rdkit.Chem import Draw**

** File “/home/appuser/venv/lib/python3.7/site-packages/rdkit/Chem/Draw/init.py”, line 14, in **

** from rdkit.Chem.Draw import rdMolDraw2D**

ImportError: libXrender.so.1: cannot open shared object file: No such file or directory

Hi @sgehl,

It looks like libxrender1 is an apt-get dependency for rdkit-python.

You will have to create a packages.txt file with the following entry:

libxrender1

Once you create the :point_up: packages.txt file and reboot your app, rdkit should be imported successfully :slightly_smiling_face:

Happy Streamlit’ing! :balloon:
Snehan

1 Like

Here is my requirements.txt file:

mols2grid==0.0.6
pandas==0.25.3
streamlit==0.84.0
rdkit-pypi==2021.3.3
libxrender==0.9.10

(I tried libxrender1 but it was showing the same error)
What am I doing wrong?

Here is the error I am getting now:

ERROR: Could not find a version that satisfies the requirement libxrender==0.9.10 (from versions: none)

ERROR: No matching distribution found for libxrender==0.9.10

Previously it could not find libxrender1.

Thank you for your help :slightly_smiling_face:

Hi @sgehl,

libxrender1 should be included in a new file called packages.txt. You have accidentally included it in your requirements.txt file instead.

Remove the entry from your requirements file and include libxrender1 in packages.txt.

Best, :balloon:
Snehan