danforthcenter / plantcv

Plant phenotyping with image analysis
Mozilla Public License 2.0
666 stars 265 forks source link

(bugfix) ImportError: lxml.html.clean module is now a separate project lxml_html_clean. #1556

Closed HaleySchuhl closed 5 months ago

HaleySchuhl commented 5 months ago

Posting this to have it on record, just incase myself or another developer run into this in the future.

Describe the bug This error is print out while trying to run py.test locally on a PR branch which in the plantcv-annotate repo. Googling the error message suggests to me that it's related to a dependency of napari, however, I'm getting the same error when I attempt to run tests on branches from the main plantcv repo and the plantcv-geospatial main branch. This suggested it's an issue in my conda environment.

To test this I created a fresh conda environment using the following environment.yml, and using the same cloned repositories. Then made the software editable within the fresh environment by running pip install -e . --config-settings editable_mode=strict.

full error traceback

Traceback (most recent call last):
  File "/opt/miniconda3/envs/plantcv/bin/py.test", line 10, in <module>
    sys.exit(console_main())
             ^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/_pytest/config/__init__.py", line 197, in console_main
    code = main()
           ^^^^^^
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/_pytest/config/__init__.py", line 155, in main
    config = _prepareconfig(args, plugins)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/_pytest/config/__init__.py", line 337, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/pluggy/_hooks.py", line 501, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/pluggy/_manager.py", line 119, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/pluggy/_callers.py", line 138, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/pluggy/_callers.py", line 121, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/_pytest/helpconfig.py", line 105, in pytest_cmdline_parse
    config = yield
             ^^^^^
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/pluggy/_callers.py", line 102, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1143, in pytest_cmdline_parse
    self.parse(args)
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1492, in parse
    self._preparse(args, addopts=addopts)
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1379, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/pluggy/_manager.py", line 414, in load_setuptools_entrypoints
    plugin = ep.load()
             ^^^^^^^^^
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/importlib/metadata/__init__.py", line 202, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/_pytest/assertion/rewrite.py", line 178, in exec_module
    exec(co, module.__dict__)
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/napari/utils/__init__.py", line 8, in <module>
    from napari.utils.notebook_display import nbscreenshot
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/_pytest/assertion/rewrite.py", line 178, in exec_module
    exec(co, module.__dict__)
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/napari/utils/notebook_display.py", line 9, in <module>
    from lxml.html.clean import Cleaner
  File "/opt/miniconda3/envs/plantcv/lib/python3.11/site-packages/lxml/html/clean.py", line 18, in <module>
    raise ImportError(
ImportError: lxml.html.clean module is now a separate project lxml_html_clean.
Install lxml[html_clean] or lxml_html_clean directly.

Environment.yml

# run: conda env create --file environment.yml
# optionally, change channel name with -n {plantcv-dev}
name: plantcv
dependencies:
  - python=3.11
  - matplotlib>=1.5
  - numpy>=1.11
  - pandas
  - python-dateutil
  - scipy
  - scikit-image>=0.19
  - scikit-learn
  - dask
  - dask-jobqueue
  - opencv
  - statsmodels
  - xarray>=2022.11.0
  - mkdocs
  - pytest
  - pytest-cov
  - flake8
  - ipympl
  - nodejs
  - jupyterlab
  - altair
  - vl-convert-python
  - rasterio
  - napari
  - pytest-qt
  - pyqt
  - git

channels:
  - conda-forge
  - defaults