graspologic-org / graspologic

Python package for graph statistics
https://graspologic-org.github.io/graspologic/
MIT License
820 stars 144 forks source link

[BUG] Graspologic Layouts can fail __init__.py if `umap` is installed #637

Closed daxpryce closed 3 years ago

daxpryce commented 3 years ago

Apparently there are multiple libraries that use umap as their namespace. If the user has umap installed instead of our required umap-learn, environments can have unexpected results.

The actual fix for this is to pip uninstall umap umap-learn && pip install umap-learn to purge umap from your environment.

An argument can be made that since this is an easy trap to fall into, we should do something to alert our users that their environment isn't what we (or possibly they) expected.

Another argument could be that we should create an FAQ wiki page about problems just like this so we can tell people how to fix them going forward.

I'm not convinced we want a coding solution, but I wanted to spur a discussion about this.

Expected Behavior

import graspologic should succeed

Actual Behavior

import graspologic fails when umap is installed instead of umap-learn.

Full Traceback

Traceback (most recent call last):
  File "/app/d3m/d3m/index.py", line 174, in load_all
    get_primitive(primitive_path)
  File "/app/d3m/d3m/index.py", line 117, in get_primitive
    return getattr(module, name)
  File "/app/d3m/d3m/namespace.py", line 116, in __getattr__
    primitive = entry_point.resolve()
  File "/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py", line 2459, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/app/primitives-interfaces/jhu_primitives/__init__.py", line 26, in <module>
    from .sgm_nomination import SgmNomination
  File "/app/primitives-interfaces/jhu_primitives/sgm_nomination/__init__.py", line 2, in <module>
    from .sgm_nomination import SgmNomination
  File "/app/primitives-interfaces/jhu_primitives/sgm_nomination/sgm_nomination.py", line 12, in <module>
    from graspologic.match import GraphMatch
  File "/usr/local/lib/python3.6/dist-packages/graspologic/__init__.py", line 9, in <module>
    import graspologic.layouts
  File "/usr/local/lib/python3.6/dist-packages/graspologic/layouts/__init__.py", line 7, in <module>
    from .auto import layout_tsne, layout_umap
  File "/usr/local/lib/python3.6/dist-packages/graspologic/layouts/auto.py", line 11, in <module>
    import umap
  File "/usr/local/lib/python3.6/dist-packages/umap/__init__.py", line 2, in <module>
    from .umap_ import UMAP
  File "/usr/local/lib/python3.6/dist-packages/umap/umap_.py", line 30, in <module>
    import umap.distances as dist
AttributeError: module 'umap' has no attribute 'distances'

@alyakin314 was the one who found this and I'm sure he has some thoughts on which direction we should go with this.

bdpedigo commented 3 years ago

An argument can be made that since this is an easy trap to fall into, we should do something to alert our users that their environment isn't what we (or possibly they) expected.

Another argument could be that we should create an FAQ wiki page about problems just like this so we can tell people how to fix them going forward.

I'm not convinced we want a coding solution, but I wanted to spur a discussion about this.

This unfortunately is a common problem in Python - for instance, pip install sklearn doesn't work, which I always try to do and remember right after that it's scikit-learn. So I agree that there is no code fix we should do, but more than happy to have a FAQ page (especially for install issues) if someone wants to make one.

daxpryce commented 3 years ago

Agreed, some problems aren't super easy to fix and I would assert shouldn't be fixed via code.

For instance, one of the users in our office tried to install everything with a brand new Python 3.9 on windows. In theory most of our stuff should work, but llvmlite that numba uses doesn't have a 3.9 wheel. Then it jumped to trying to use sdist (which is fine!), but wouldn't build, because building native libraries for Python in windows is always just a bit more special than doing it on a unix variant (admittedly, I may be more negative on this than others because I know exactly what to do in Ubuntu and am reasonably confident in OSX, but in Windows I just have a sort of golden-retriever-doing-science look on my face when anything comes up).

So... that's a long winded way of saying "I should just create the FAQ page"

daxpryce commented 3 years ago

FAQ page created, entry added.