enthought / chaco

Chaco is a Python package for building interactive and custom 2-D plots.
http://docs.enthought.com/chaco/
Other
291 stars 101 forks source link

ModuleNotFoundError: No module named 'pyface.ui.qt4.color' when running demos related to enable/enable/trait_defs/ui/qt4/rgba_color_editor.py #886

Closed homosapien-lcy closed 1 year ago

homosapien-lcy commented 1 year ago

Problem Description ModuleNotFoundError: No module named 'pyface.ui.qt4.color' when running multiple demos using enable/enable/trait_defs/ui/qt4/rgba_color_editor

Reproduction Steps:

python3.11 3.11_test/chaco/examples/tutorials/scipy2008/traits_example.py

OS, Python version: [MacOS, python 3.11]

Packages: (py311) (base) cyliu@aus552cyliu Documents % python3.11 -m pip list Package Version Editable project location


chaco 5.1.0 /Users/cyliu/Documents/3.11_test/chaco configobj 5.0.8 enable 5.4.0.dev25 /Users/cyliu/Documents/3.11_test/enable fonttools 4.39.2 joblib 1.2.0 numpy 1.24.2 pandas 1.5.3 Pillow 9.4.0 pip 22.3.1 PyAudio 0.2.13 pyface 8.0.0 pygarrayimage 1.0 pyglet 2.0.5 Pygments 2.14.0 pyparsing 3.0.9 PySide6 6.4.3 PySide6-Addons 6.4.3 PySide6-Essentials 6.4.3 python-dateutil 2.8.2 pytz 2023.2 reportlab 3.6.12 scikit-learn 1.2.2 scipy 1.10.1 setuptools 65.6.3 shiboken6 6.4.3 six 1.16.0 threadpoolctl 3.1.0 traits 6.4.1 traitsui 7.4.3

homosapien-lcy commented 1 year ago

I think the way to solve this is to introduce ShadowedModuleFinder in the enable root folder, so that all files using qt4 can import this function from it. Then we will do the module finder for each deprecated imports.

dpinte commented 1 year ago

@homosapien-lcy

Can you please format your tickets with links to the files causing issues, make sure you expose the full traceback and provide an issue title that is clear?

  1. Issue title: ModuleNotFoundError: No module named 'pyface.ui.qt4.color' is not clear at all. As far as I guess looking at the description, the error is not a chaco error but an error in enable. So if you report a problem in the Chaco repository, what are you reporting? The issue is a probem executing the tutorials/scipy2008/traits_example.py example, no? And that one could link to a ticket in the enable repository regarding the ModuleNotFoundError on a given file from the enable library.

  2. Issue description:

    • why are you not reporting the entire traceback?
    • why don't you add links to the target files? if you don't anyone looking at the code will need to search for the file
    • In the problem description, you mention "when running multiple demos using". Is this ticket about the traits_example.py or other demos? It has to be clear.
    • Github is great at formatting output of commands or code when you put the text between three backticks. That also helps

When you add the full traceback, you get more specific information regarding the error than what you reported:

(ets38)bash-3.2$ python examples/tutorials/scipy2008/traits_example.py
/Users/dpinte/.edm/envs/ets38/lib/python3.8/site-packages/enable/trait_defs/ui/qt4/rgba_color_editor.py:19: FutureWarning: The pyface.ui.qt4.* modules have moved to pyface.ui.qt.*.

Applications which require backwards compatibility can either:

- set the ETS_QT4_IMPORTS environment variable
- set the ETS_TOOLKIT environment variable to "qt4",
- the ETSConfig.toolkit to "qt4"
- install pyface.ui.ShadowedModuleFinder() into sys.meta_path

  from pyface.ui.qt4.color import toolkit_color_to_rgba, rgba_to_toolkit_color
Traceback (most recent call last):
  File "examples/tutorials/scipy2008/traits_example.py", line 3, in <module>
    from enable.api import ColorTrait, marker_trait
  File "/Users/dpinte/.edm/envs/ets38/lib/python3.8/site-packages/enable/api.py", line 184, in <module>
    from .base import (
  File "/Users/dpinte/.edm/envs/ets38/lib/python3.8/site-packages/enable/base.py", line 41, in <module>
    from .colors import color_table, transparent_color
  File "/Users/dpinte/.edm/envs/ets38/lib/python3.8/site-packages/enable/colors.py", line 20, in <module>
    from enable.trait_defs.ui.rgba_color_editor import (
  File "/Users/dpinte/.edm/envs/ets38/lib/python3.8/site-packages/enable/trait_defs/ui/rgba_color_editor.py", line 15, in <module>
    from .qt4.rgba_color_editor import RGBAColorEditor
  File "/Users/dpinte/.edm/envs/ets38/lib/python3.8/site-packages/enable/trait_defs/ui/qt4/rgba_color_editor.py", line 19, in <module>
    from pyface.ui.qt4.color import toolkit_color_to_rgba, rgba_to_toolkit_color
ModuleNotFoundError: No module named 'pyface.ui.qt4.color'

Based on the error message above, it is clear that a user can get the example to work by settings the ETS_TOOLKIT variable:

(ets38)bash-3.2$ ETS_TOOLKIT=qt4 python examples/tutorials/scipy2008/traits_example.py
QCssParser::parseColorValue: Specified color without alpha value but alpha given: 'rgb 0,0,0,255'
QCssParser::parseColorValue: Specified color without alpha value but alpha given: 'rgb 0,0,128,255'
QCssParser::parseColorValue: Specified color without alpha value but alpha given: 'rgb 0,0,255,255'
...

Now, to the underlying cause. Yes, the issue comes from the fact that enable has not made its transition from qt4 to qt like pyface did. The transition has started with https://github.com/enthought/enable/pull/1028 but it needs some more work on enable/trait_defs/ui/qt4. A specific issue should be opened in the enable repository.