[Python] Why does an rdkit function only work when I import something else?

Discussão em 'Python' iniciado por Stack, Julho 9, 2025.

  1. Stack

    Stack Membro Participativo

    There is something seriously strange going on here with RDKit's imports that I don't understand.

    I am using some basic functionality (as per their documentation) like so:

    from rdkit import Chem

    # Create a molecule from a SMILES pattern (arbitrarily chosen for this example)
    mol = Chem.MolFromSmiles('CCCC')

    # Calculate its molecular weight
    print(Chem.Descriptors.ExactMolWt(mol))


    Except, this doesn't work.


    AttributeError: module 'rdkit.Chem' has no attribute 'Descriptors'
    ​

    However, if I add an import line at the top: from rdkit.Chem import Descriptors. Now it works.


    58.078250319999995
    ​

    Note, I HAVE NOT CHANGED ANY OF THE REST OF THE CODE. Only the import, which I do not use directly!

    What on earth is going on here?

    Continue reading...

Compartilhe esta Página