# Python not loading rdkit

**URL:** <https://forum.knime.com/t/python-not-loading-rdkit/59489>\
**Category:** KNIME Analytics Platform\
**Created:** [January 15, 2023, 11:27am UTC](https://forum.knime.com/t/python-not-loading-rdkit/59489 "2023-01-15T11:27:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![evert.homan\_scilifelab.se](https://forum-cdn.knime.com/user_avatar/forum.knime.com/evert.homan_scilifelab.se/32/18181_2.png) [@evert.homan\_scilifelab.se](https://forum.knime.com/u/evert.homan_scilifelab.se)\
**Post date:** [January 15, 2023, 11:27am UTC](https://forum.knime.com/t/python-not-loading-rdkit/59489/1 "2023-01-15T11:27:12Z")

</div>

Hi,

I am trying to recreate a workflow described here:

> **[Generate molecules with REINVENT and make interactive plot #RDKit #Knime...](https://iwatobipen.wordpress.com/2022/09/03/generate-molecules-with-reinvent-and-make-interactive-plot-rdkit-knime-reinvent/)**
>
> I introduced to use user defined condaenv in Knime. It’s really useful I think. And as you know, REINVENT is the one of famous compound generation tool for drug discovery. Its community provi…

I asked the author to uploade the workflow to the Knime hub but without aveil so far, hence I am trying to recreate it from the written material.

I have installed Reinvent 3.2 according to [GitHub - MolecularAI/Reinvent · GitHub](https://github.com/MolecularAI/Reinvent) using miniconda. I can activate the environment packages using the Conda Environment Propagation node, and see all packages installed in the Reinvent.v3.2 environment. In the Python Source node I enter the code from the blog:

from pandas import DataFrame

# Create empty table

output\_table = DataFrame()  
from rdkit import Chem  
import sys  
print(sys.path)  
import reinvent\_models.reinvent\_core.models.model as reinvent  
batchsize = 124  
#model path where user would like to use  
modelpath = ‘/tmp/evehom/random.prior.new’

model = reinvent.Model.load\_from\_file(modelpath, sampling\_mode=True)  
sampled\_smi, likelyhood = model.sample\_smiles(batchsize)  
output\_table[‘sampled\_smi’] = sampled\_smi  
output\_table[‘likelyhood’] = likelyhood  
output\_table[‘ROMol’] = output\_table[‘sampled\_smi’] .apply(Chem.MolFromSmiles)

Running this gives:

ERROR Python Source 3:2 Execute failed: No module named ‘rdkit’  
Traceback (most recent call last):  
File “”, line 4, in   
ModuleNotFoundError: No module named ‘rdkit’

Yet rdkit is listed in the environment package list. One thing I noted is that in Knime it says rdkit version 2020.03.3.0. while if I activate the same env command line and check the version it says 2022.03.2.

Either way I don’t understand why the rdkit error message comes up since the package is installed.

Thanks for any pointer to a Python noob.

[Reinvent.knwf](https://forum.knime.com/uploads/short-url/5sBjlXrieurk8vsjTVdkAL5s20w.knwf) (13.0 KB)

---

<div class="post-metadata">

**Author:** ![steffen\_KNIME](https://forum-cdn.knime.com/user_avatar/forum.knime.com/steffen_knime/32/33719_2.png) [@steffen\_KNIME](https://forum.knime.com/u/steffen_KNIME)\
**Post date:** [January 16, 2023, 8:12am UTC](https://forum.knime.com/t/python-not-loading-rdkit/59489/2 "2023-01-16T08:12:20Z")

</div>

Hi,

from what you provide, there seem to be two things mixed in the KNIME Analytics Platform: the global Python environment (See `Preferences -> KNIME -> Python (or Python(Legacy))`) versus the environment you created with your Conda Environment Propagation node. The latter does not include `RDKit` and will thus fail.  
First: you can delete the link between the two nodes in your workflow and try it with your global Python environment.

Second: see [this link for the usage of the Conda Environment Propagation node](https://www.knime.com/blog/how-to-manage-python-environments-conda-and-knime) and [this link on how to use the latest Python integration](https://docs.knime.com/latest/python_installation_guide/#_introduction) for further details.

Third: I am wondering, where in KNIME does it say that it has the version _2020.03.3.0_? Because that cannot be within the node.

Fourth: if all that does not help, please provide the installed packages of your used Python environment as a txt file (see _Second_ on how to check which Python environment is currently used).

Fifth: please format code in forum posts 🙂

Does this answer your question? Don’t hesitate to ask further questions!

Best regards  
Steffen

---

<div class="post-metadata">

**Author:** ![evert.homan\_scilifelab.se](https://forum-cdn.knime.com/user_avatar/forum.knime.com/evert.homan_scilifelab.se/32/18181_2.png) [@evert.homan\_scilifelab.se](https://forum.knime.com/u/evert.homan_scilifelab.se)\
**Post date:** [January 16, 2023, 1:05pm UTC](https://forum.knime.com/t/python-not-loading-rdkit/59489/3 "2023-01-16T13:05:17Z")

</div>

Hi,

#1: after deleting the link and setting the global Python environment to reinvent.v3.2 it (sort of) works. At least rdkit gets loaded (but I get another error further down the code, which is not due to missing packages)

#2: my interpretation of the Conda Environment Propagation node was that you can use it to ‘bypass’ the global Python preferences in a workflow-specific manner but this is not the case?

#3: see screenshot from the Conda Environment Propagation node configuration, where it says rdkit 2020.03.3.0. Note that this environment was created outside Knime according to the Reinvent gihub instructions. On the command line the rdkit version in this environment is 2022.03.2  
(py39h89e00b9\_0):

 ![KNIME_rdkit_error](https://forum-cdn.knime.com/uploads/default/original/3X/8/e/8e393726c88aa9c9dcb5d0c193279ac3e6b35b3e.png)

#4: since it seems to work by setting the global python env to reinvent this is not necessary

#5: not sure how to do this

---

<div class="post-metadata">

**Author:** ![steffen\_KNIME](https://forum-cdn.knime.com/user_avatar/forum.knime.com/steffen_knime/32/33719_2.png) [@steffen\_KNIME](https://forum.knime.com/u/steffen_KNIME)\
**Post date:** [January 16, 2023, 2:00pm UTC](https://forum.knime.com/t/python-not-loading-rdkit/59489/4 "2023-01-16T14:00:42Z")

</div>

Hi,

1. Seems to be an issue with your Python environment `reinvent.v3.2`, let me know if there are further issues installing missing packages.

2. Yes you can, but that requires a working Python environment. I suggest using a global Python environment first, complete your script and then make the Conda Environment Propagation node use the Python environment. If it works, you can use it to bypass the global preferences. The node should then also use the current Python version and not refer to some old version anymore.

3. It seems like the workflow you shared had another Conda environment configured, thus my confusion. I get the following environment displayed:  

4. 👍

5. The (maybe not intuitive) symbols when writing a post provide formatting options: mark a whole script and click `Preformatted text`  

If you have further questions, don’t hesitate to ask!

Best regards  
Steffen

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [January 16, 2023, 3:35pm UTC](https://forum.knime.com/t/python-not-loading-rdkit/59489/5 "2023-01-16T15:35:31Z")

</div>

@evert.homan_scilifelab.se these remarks: I would not use dots in the name of my conda environment. Try to limit the special characters to just underscore.

Then you might want to take a look at my article about KNIME and conda environments and mabye create a YAML file that would contain all your necessary libraries and try to install vis this configuration:

> **[KNIME and Python — Setting up and managing Conda environments](https://medium.com/low-code-for-advanced-data-science/knime-and-python-setting-up-and-managing-conda-environments-2ac217792539)**
>
> TL;DR: install python/conda thru Miniforge, find and use specific YAML-files to manage an environment, tell KNIME and use their…

Then follow the official guise how to make sure your [Python Script node](https://hub.knime.com/knime/extensions/org.knime.features.python3.scripting/latest/org.knime.python3.scripting.nodes.script.PythonScriptNodeFactory/) knows which environment to use. I would use the new ones: I think your screenshots shows a deprecated one.

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [April 16, 2023, 3:35pm UTC](https://forum.knime.com/t/python-not-loading-rdkit/59489/6 "2023-04-16T15:35:31Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
