Add a function to build a directed graph for the solutions
Raise TypeError when comparing different packages instead of ValueError

This is more consistent with standard Python behavior, and makes it easier to
deal with these things.