Search code examples
pythonimporterror

Cannot get TopologicalSorter from graphlib


I did

pip3 install graphlib

I can now import graphlib, but

from graphlib import TopologicalSorter

fails. If I import graphlib, it tells me that there is no attibute TopologicalSorter.

What am I doing wrong?


Solution

  • Confusingly, graphlib on PyPI is not the real graphlib, so you don’t have the right package installed.

    You need to replace graphlib’s evil twin with the real thing:

    pip3 uninstall graphlib
    pip3 install graphlib-backport