conda-forge / scikit-image-feedstock

A conda-smithy repository for scikit-image.
BSD 3-Clause "New" or "Revised" License
4 stars 25 forks source link

Required dependency `matplotlib` is not installed #99

Closed ehusby closed 1 year ago

ehusby commented 1 year ago

Solution to issue cannot be found in the documentation.

Issue

Test environment was created with the following command:

create -n test-skimage scikit-image

matplotlib is a required package for some skimage functions such as skimage.draw.polygon_perimeter. Below is an example usage that raises the error.

Python 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:27:40) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import skimage
>>> from skimage.draw import polygon_perimeter
>>> polygon_perimeter([0,1,1,0,0],[0,0,1,1,0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/husby036/installed/build/miniconda3_rookery2/envs/test-skimage/lib/python3.11/site-packages/skimage/_shared/version_requirements.py", line 151, in func_wrapped
    raise ImportError(msg + '"')
ImportError: "<function polygon_perimeter at 0x7ff9cc412de0>" in "skimage.draw.draw" requires "matplotlib >=3.0.3"
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'matplotlib'

If I manually install the matplotlib package into the conda environment, then there is no error.

For reference, here are the contents of my ~/.condarc file:

auto_activate_base: false
channels:
  - conda-forge
  - defaults

Installed packages

# packages in environment at /home/husby036/installed/build/miniconda3_rookery2/envs/test-skimage:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
aom                       3.5.0                h27087fc_0    conda-forge
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
blosc                     1.21.3               hafa529b_0    conda-forge
brotli                    1.0.9                h166bdaf_8    conda-forge
brotli-bin                1.0.9                h166bdaf_8    conda-forge
brotlipy                  0.7.0           py311hd4cff14_1005    conda-forge
brunsli                   0.1                  h9c3ff4c_0    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
c-ares                    1.18.1               h7f98852_0    conda-forge
c-blosc2                  2.7.1                hf91038e_0    conda-forge
ca-certificates           2022.12.7            ha878542_0    conda-forge
certifi                   2022.12.7          pyhd8ed1ab_0    conda-forge
cffi                      1.15.1          py311h409f033_3    conda-forge
cfitsio                   4.2.0                hd9d235c_0    conda-forge
charls                    2.4.1                hcb278e6_0    conda-forge
charset-normalizer        2.1.1              pyhd8ed1ab_0    conda-forge
click                     8.1.3           unix_pyhd8ed1ab_2    conda-forge
cloudpickle               2.2.1              pyhd8ed1ab_0    conda-forge
cryptography              39.0.1          py311h9b4c7bb_0    conda-forge
cytoolz                   0.12.0          py311hd4cff14_1    conda-forge
dask-core                 2023.2.0           pyhd8ed1ab_0    conda-forge
dav1d                     1.0.0                h166bdaf_1    conda-forge
freetype                  2.12.1               hca18f0e_1    conda-forge
fsspec                    2023.1.0           pyhd8ed1ab_0    conda-forge
giflib                    5.2.1                h36c2ea0_2    conda-forge
idna                      3.4                pyhd8ed1ab_0    conda-forge
imagecodecs               2023.1.23       py311ha5a3c35_0    conda-forge
imageio                   2.25.1             pyh24c5eb1_0    conda-forge
jpeg                      9e                   h0b41bf4_3    conda-forge
jxrlib                    1.1                  h7f98852_2    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
krb5                      1.20.1               h81ceb04_0    conda-forge
lcms2                     2.14                 hfd0df8a_1    conda-forge
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libaec                    1.0.6                hcb278e6_1    conda-forge
libavif                   0.11.1               h5cdd6b5_0    conda-forge
libblas                   3.9.0           16_linux64_openblas    conda-forge
libbrotlicommon           1.0.9                h166bdaf_8    conda-forge
libbrotlidec              1.0.9                h166bdaf_8    conda-forge
libbrotlienc              1.0.9                h166bdaf_8    conda-forge
libcblas                  3.9.0           16_linux64_openblas    conda-forge
libcurl                   7.88.1               hdc1c0ab_0    conda-forge
libdeflate                1.17                 h0b41bf4_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 12.2.0              h65d4601_19    conda-forge
libgfortran-ng            12.2.0              h69a702a_19    conda-forge
libgfortran5              12.2.0              h337968e_19    conda-forge
libgomp                   12.2.0              h65d4601_19    conda-forge
liblapack                 3.9.0           16_linux64_openblas    conda-forge
libnghttp2                1.51.0               hff17c54_0    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libopenblas               0.3.21          pthreads_h78a6416_3    conda-forge
libpng                    1.6.39               h753d276_0    conda-forge
libsqlite                 3.40.0               h753d276_0    conda-forge
libssh2                   1.10.0               hf14f497_3    conda-forge
libstdcxx-ng              12.2.0              h46fd767_19    conda-forge
libtiff                   4.5.0                h6adf6a1_2    conda-forge
libuuid                   2.32.1            h7f98852_1000    conda-forge
libwebp-base              1.2.4                h166bdaf_0    conda-forge
libxcb                    1.13              h7f98852_1004    conda-forge
libzlib                   1.2.13               h166bdaf_4    conda-forge
libzopfli                 1.0.3                h9c3ff4c_0    conda-forge
locket                    1.0.0              pyhd8ed1ab_0    conda-forge
lz4-c                     1.9.4                hcb278e6_0    conda-forge
ncurses                   6.3                  h27087fc_1    conda-forge
networkx                  3.0                pyhd8ed1ab_0    conda-forge
numpy                     1.24.2          py311h8e6699e_0    conda-forge
openjpeg                  2.5.0                hfec8fc6_2    conda-forge
openssl                   3.0.8                h0b41bf4_0    conda-forge
packaging                 23.0               pyhd8ed1ab_0    conda-forge
partd                     1.3.0              pyhd8ed1ab_0    conda-forge
pillow                    9.4.0           py311h50def17_1    conda-forge
pip                       23.0.1             pyhd8ed1ab_0    conda-forge
pooch                     1.6.0              pyhd8ed1ab_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pyopenssl                 23.0.0             pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
python                    3.11.0          he550d4f_1_cpython    conda-forge
python_abi                3.11                    3_cp311    conda-forge
pywavelets                1.4.1           py311hcb2cf0a_0    conda-forge
pyyaml                    6.0             py311hd4cff14_5    conda-forge
readline                  8.1.2                h0f457ee_0    conda-forge
requests                  2.28.2             pyhd8ed1ab_0    conda-forge
scikit-image              0.19.3          py311h8b32b4d_2    conda-forge
scipy                     1.10.1          py311h8e6699e_0    conda-forge
setuptools                67.4.0             pyhd8ed1ab_0    conda-forge
snappy                    1.1.9                hbd366e4_2    conda-forge
tifffile                  2023.2.3           pyhd8ed1ab_0    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
toolz                     0.12.0             pyhd8ed1ab_0    conda-forge
tzdata                    2022g                h191b570_0    conda-forge
urllib3                   1.26.14            pyhd8ed1ab_0    conda-forge
wheel                     0.38.4             pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.9                h7f98852_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
yaml                      0.2.5                h7f98852_2    conda-forge
zfp                       1.0.0                h27087fc_3    conda-forge
zlib-ng                   2.0.6                h166bdaf_0    conda-forge
zstd                      1.5.2                h3eb15da_6    conda-forge

Environment info

active environment : test-skimage
    active env location : /home/husby036/installed/build/miniconda3_rookery2/envs/test-skimage
            shell level : 2
       user config file : /home/husby036/.condarc
 populated config files : /home/husby036/.condarc
          conda version : 22.11.1
    conda-build version : not installed
         python version : 3.10.8.final.0
       virtual packages : __archspec=1=x86_64
                          __glibc=2.28=0
                          __linux=4.18.0=0
                          __unix=0=0
       base environment : /home/husby036/installed/build/miniconda3_rookery2  (writable)
      conda av data dir : /home/husby036/installed/build/miniconda3_rookery2/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/husby036/installed/build/miniconda3_rookery2/pkgs
                          /home/husby036/.conda/pkgs
       envs directories : /home/husby036/installed/build/miniconda3_rookery2/envs
                          /home/husby036/.conda/envs
               platform : linux-64
             user-agent : conda/22.11.1 requests/2.28.1 CPython/3.10.8 Linux/4.18.0-372.32.1.el8_6.x86_64 rocky/8.7 glibc/2.28
                UID:GID : 657378:1328160511
             netrc file : None
           offline mode : False
hmaarrfk commented 1 year ago

I think oddly enough, this was the one dependency we decided was this one function, was not a reason to drag in a heavy dependency, by default to all users of scikit-image.

I think you might be able to follow the decision process https://github.com/scikit-image/scikit-image/pull/5990

But TLDR, you need to install matplotlib yourself if you want to use this one function.

ocefpaf commented 1 year ago

Yep. mpl is optional and that is not a bug. See https://github.com/scikit-image/scikit-image/blob/main/pyproject.toml#L106-L113

ehusby commented 1 year ago

Got it! I wonder if there's a standard way of making that more obvious in either the scikit-image source code, or in this conda-forge feedstock. It's only a little concerning to discover this at runtime.

ocefpaf commented 1 year ago

It's only a little concerning to discover this at runtime.

Why? The error message tells you that mpl is missing and it is easy to solve by installing it. All Python packages use that logic for optional dependencies. If you are pip-installing you can add all the optional packages with the pip install scikit-image[optional] syntax. Note that there is no way for the end user to find out the names of the optional "options" without reading the package metadata.

hmaarrfk commented 1 year ago

This can be improved by adding code to scikit image.

Just, it is "one more thing" and as ocefpaf said, is it any different than the provided error message? Adding more code, more features, more options, generally adds maintenance burden.

It's a delicate balance