Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Namespace clash with colour package. #958

Closed
mforbes opened this issue Mar 11, 2022 · 4 comments
Closed

[BUG]: Namespace clash with colour package. #958

mforbes opened this issue Mar 11, 2022 · 4 comments

Comments

@mforbes
Copy link

mforbes commented Mar 11, 2022

Description

The colour namespace used by this package collides with the colour package. Usually this is not a problem when packages have the same name as their project namespace (since these must be unique on PyPI) but since this project uses the name colour-science, the usual collision avoidance does not work.

Is there a way to configure colour-science to coexist with the colour package?

My actual issue is that I am using manim which depends on colour, so the solution suggested on stack overflow will not work unless I modify manim.

Code for Reproduction

$ python3 -m venv cs
$ . cs/bin/activate
(cs) $ pip install colour
...
Successfully installed colour-0.1.5
(cs) $ python -c "import colour; print(colour.Color)"
<class 'colour.Color'>
(cs) $ pip install colour-science
...
Successfully installed colour-science-0.4.1 imageio-2.16.1 numpy-1.22.3 pillow-9.0.1 scipy-1.8.0 typing-extensions-4.1.1
(cs) $ python -c "import colour; print(colour.Color)"
...
AttributeError: module 'colour' has no attribute 'Color'

Exception Message

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../cs/lib/python3.8/site-packages/colour/__init__.py", line 874, in __getattr__
    return super().__getattr__(attribute)
  File ".../cs/lib/python3.8/site-packages/colour/utilities/deprecation.py", line 374, in __getattr__
    return getattr(self._module, attribute)
AttributeError: module 'colour' has no attribute 'Color'

Environment Information

===============================================================================
*                                                                             *
*   Interpreter :                                                             *
*       python : 3.8.12 | packaged by conda-forge | (default, Jan 30 2022,    *
*   23:33:09)                                                                 *
*                [Clang 11.1.0 ]                                              *
*                                                                             *
*   colour-science.org :                                                      *
*       colour : 0.4.1                                                        *
*                                                                             *
*   Runtime :                                                                 *
*       imageio : 2.16.1                                                      *
*       numpy : 1.22.3                                                        *
*       scipy : 1.8.0                                                         *
*                                                                             *
===============================================================================
@mforbes mforbes added the Defect label Mar 11, 2022
@KelSolaar
Copy link
Member

Hi @mforbes,

Yes this is a known issue, it is the first time though that someone reports it in almost 8 years! :) You will also note that the author of the colour package had the same kind of issue back then because the color namespace was used: all is objects are called Color or refer to color.

So while there is no elegant solution, there is a dirty one that should hopefully work for you, i.e. namespace merging which is easy because colour.py is a single file:

python3 -m venv colour-science-colour
source colour-science-colour/bin/activate
pip install colour
mv colour-science-colour/lib/python3.9/site-packages/colour.py colour-science-colour/lib/python3.9/site-packages/color.py
pip install colour-science
echo "from color import *" >> colour-science-colour/lib/python3.9/site-packages/colour/__init__.py

The steps run in a shell with output:

Eris:Environments kelsolaar$ python3 -m venv colour-science-colour
Eris:Environments kelsolaar$ source colour-science-colour/bin/activate
(colour-science-colour) Eris:Environments kelsolaar$ pip install colour
Collecting colour
  Using cached colour-0.1.5-py2.py3-none-any.whl (23 kB)
Installing collected packages: colour
Successfully installed colour-0.1.5
WARNING: You are using pip version 21.3.1; however, version 22.0.4 is available.
You should consider upgrading via the '/Users/kelsolaar/Documents/Development/Environments/colour-science-colour/bin/python3.9 -m pip install --upgrade pip' command.
(colour-science-colour) Eris:Environments kelsolaar$ mv colour-science-colour/lib/python3.9/site-packages/colour.py colour-science-colour/lib/python3.9/site-packages/color.py
(colour-science-colour) Eris:Environments kelsolaar$ pip install colour-science
Collecting colour-science
  Using cached colour_science-0.4.1-py3-none-any.whl (2.2 MB)
Collecting imageio<3,>=2
  Using cached imageio-2.16.1-py3-none-any.whl (3.3 MB)
Collecting numpy<2,>=1.19
  Using cached numpy-1.22.3-cp39-cp39-macosx_11_0_arm64.whl (12.8 MB)
Collecting scipy<2,>=1.5
  Using cached scipy-1.8.0-cp39-cp39-macosx_12_0_arm64.whl (28.7 MB)
Collecting typing-extensions<5,>=4
  Using cached typing_extensions-4.1.1-py3-none-any.whl (26 kB)
Collecting pillow>=8.3.2
  Using cached Pillow-9.0.1-1-cp39-cp39-macosx_11_0_arm64.whl (2.7 MB)
Installing collected packages: pillow, numpy, typing-extensions, scipy, imageio, colour-science
Successfully installed colour-science-0.4.1 imageio-2.16.1 numpy-1.22.3 pillow-9.0.1 scipy-1.8.0 typing-extensions-4.1.1
WARNING: You are using pip version 21.3.1; however, version 22.0.4 is available.
You should consider upgrading via the '/Users/kelsolaar/Documents/Development/Environments/colour-science-colour/bin/python3.9 -m pip install --upgrade pip' command.
(colour-science-colour) Eris:Environments kelsolaar$ echo "from color import *" >> colour-science-colour/lib/python3.9/site-packages/colour/__init__.py
(colour-science-colour) Eris:Environments kelsolaar$ python
Python 3.9.9 (main, Nov 21 2021, 03:16:13)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import colour
>>> colour.Color
<class 'color.Color'>
>>> colour.utilities.describe_environment()
===============================================================================
*                                                                             *
*   Interpreter :                                                             *
*       python : 3.9.9 (main, Nov 21 2021, 03:16:13)                          *
*                [Clang 13.0.0 (clang-1300.0.29.3)]                           *
*                                                                             *
*   colour-science.org :                                                      *
*       colour : 0.4.1                                                        *
*                                                                             *
*   Runtime :                                                                 *
*       imageio : 2.16.1                                                      *
*       numpy : 1.22.3                                                        *
*       scipy : 1.8.0                                                         *
*                                                                             *
===============================================================================
defaultdict(<class 'dict'>, {'Interpreter': {'python': '3.9.9 (main, Nov 21 2021, 03:16:13) \n[Clang 13.0.0 (clang-1300.0.29.3)]'}, 'colour-science.org': {'colour': '0.4.1'}, 'Runtime': {'imageio': '2.16.1', 'numpy': '1.22.3', 'scipy': '1.8.0'}})

@mforbes
Copy link
Author

mforbes commented Mar 11, 2022

@KelSolaar Thanks for the suggestion. Any idea how I tell Poetry or Anaconda Project to do this? They don't currently allow hooks. Would it be possible to have a [colour] extra in colour-science that does this somehow on install?

@KelSolaar
Copy link
Member

Mmmh, I don't think it is possible unfortunately!

@KelSolaar KelSolaar modified the milestones: v9.9.9, v0.4.2 May 6, 2022
@KelSolaar
Copy link
Member

I will close this one as there is not much we can do about it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants