dtreeviz icon indicating copy to clipboard operation
dtreeviz copied to clipboard

ImportError: cannot import name 'Color' from 'colour' (unknown location)

Open hop-soellingeraj opened this issue 2 years ago • 10 comments

Have an issue with an import

% python3.8 -m pip install colour
Requirement already satisfied: colour in /Users/***/miniconda3/lib/python3.8/site-packages (0.1.5)
% python3.8
Python 3.8.11 (default, Jul 29 2021, 14:57:32) 
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import colour
>>> from colour import Color
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Color' from 'colour' (unknown location)

Here's the full stack trace

> python3.8 -m ***.pricing.scripts.appraisal.build_dataloader_from_title_matched
Traceback (most recent call last):
  File "/Users/***/miniconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/***/miniconda3/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/***code/***/pricing/scripts/appraisal/build_dataloader_from_title_matched.py", line 4, in <module>
    from ***.pricing.pricing.appraisal_tools import *
  File "/Users/***/code/***/pricing/pricing/appraisal_tools.py", line 17, in <module>
    from dtreeviz.trees import *
  File "/Users/***/miniconda3/lib/python3.8/site-packages/dtreeviz/__init__.py", line 3, in <module>
    from dtreeviz.classifiers import clfviz
  File "/Users/***/miniconda3/lib/python3.8/site-packages/dtreeviz/classifiers.py", line 8, in <module>
    from colour import Color
ImportError: cannot import name 'Color' from 'colour' (unknown location)

Thanks

hop-soellingeraj avatar Aug 02 '22 18:08 hop-soellingeraj

I actually question the usage of colour as a dependency at all. The last time colour was updated was 2017 and the package itself on github is structured incorrectly. I don't even know how this works for some people.

hop-soellingeraj avatar Aug 02 '22 18:08 hop-soellingeraj

@parrt do you remember why we need this line in dtreeviz/init.py ? "from dtreeviz.classifiers import clfviz"

It seems to be a visualisation method... so it doesn't add something to the code logic itself.

tlapusan avatar Aug 03 '22 08:08 tlapusan

@hop-soellingeraj I'm using colour==0.1.5 and the imports are working fine.

tlapusan avatar Aug 03 '22 08:08 tlapusan

I forgot to update this. I upon further investigation, the problem was that I am also using a package called colour-science. https://www.colour-science.org/

Unfortunately, they both have the package name colour and when colour-science is installed it breaks colour. I reported the issue to colour however I doubt anyone will do anything. That colour package seems to be unsupported for some time now.

You should be able to reproduce the issue I was having by installing colour-science.

I actually thought pypi forced package naming uniqueness, so this was a first for me.

hop-soellingeraj avatar Aug 03 '22 15:08 hop-soellingeraj

Is there a way for us to simply use an alias or something for the import to avoid a collision?

parrt avatar Aug 05 '22 20:08 parrt

we can check some stackoverflow threads like this https://stackoverflow.com/questions/27308293/how-to-install-python-package-with-a-different-name-using-pip, but for the first glance there doesn't seem to be an elegant way.

tlapusan avatar Aug 08 '22 11:08 tlapusan

Maybe we don't use colour package for very much and can borrow code if under permissive license?

parrt avatar Aug 13 '22 22:08 parrt

Could be an option, this is the license statement : https://raw.githubusercontent.com/vaab/colour/master/LICENSE

@parrt could you take also a look on it ? "1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer."

tlapusan avatar Aug 16 '22 06:08 tlapusan

It looks like the 2-clause BSD license. What is the minimal bit of code we need from them? We could simply pull in the function and then put that license on top of the function. Or we could use their ideas and implement it ourselves.

parrt avatar Aug 19 '22 00:08 parrt