luispedro / mahotas

Computer Vision in Python
https://mahotas.rtfd.io
Other
839 stars 147 forks source link

Can't import mahotas.polygon on AWS Ubuntu 20.04 when inside CellProfiler #117

Closed bethac07 closed 4 years ago

bethac07 commented 4 years ago

I think this is more likely a CellProfiler issue or a "missing ubuntu library" issue, but as I'm less familiar with mahotas import errors hoping the solution will be obvious to someone here. Otherwise, feel free to close.

Detailed here, but I set up a clean AWS Ubuntu 20.04 instance to run some tests per these instructions. Mahotas seems to install fine, and the following runs without error in python 3.8.2.

>>> import mahotas
>>> mahotas.__version__
'1.4.11'
>>> import skimage.data
>>> a = skimage.data.camera()
>>> mahotas.polygon.line((0,0),(1,1),a)

The two installed CellProfiler modules that require mahotas (or mahotas.features) fail to import it, with identical failed import strings:

Could not load cellprofiler.modules.watershed
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.8/site-packages/cellprofiler_core/utilities/core/modules/__init__.py", line 71, in add_module
    m = __import__(mod, globals(), locals(), ["__all__"], 0)
  File "/home/ubuntu/CellProfiler/cellprofiler/modules/watershed.py", line 2, in <module>
    import mahotas
  File "/home/ubuntu/.local/lib/python3.8/site-packages/mahotas/__init__.py", line 83, in <module>
    from . import polygon
  File "/home/ubuntu/.local/lib/python3.8/site-packages/mahotas/polygon.py", line 8, in <module>
    from . import _convex
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in position 0: invalid continuation byte

Any ideas? Thanks!

luispedro commented 4 years ago

Sorry, this seems strange: if mahotas imports OK when you run it on the shell, it seems that it should also work on from cellprofiler

Can you run:

import mahotas
mahotas.test()

? This may require pytest to be available, so it may fail for that reason.

bethac07 commented 4 years ago

I definitely agree that it's weird! A second 20.04 user has confirmed it though, so whatever the error is, it's reproducible across machines.

Thanks so much for taking a look at all!

From the shell:

ubuntu@ip-XXXXXXXXX:~$ python3
Python 3.8.2 (default, Jul 16 2020, 14:00:26) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mahotas
>>> mahotas.test()
================================================================================================== test session starts ==================================================================================================
platform linux -- Python 3.8.2, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /home/ubuntu
collected 307 items                                                                                                                                                                                                     

.local/lib/python3.8/site-packages/mahotas/tests/test_bbox.py .......                                                                                                                                             [  2%]
.local/lib/python3.8/site-packages/mahotas/tests/test_bwperim.py .                                                                                                                                                [  2%]
.local/lib/python3.8/site-packages/mahotas/tests/test_center_of_mass.py .....                                                                                                                                     [  4%]
.local/lib/python3.8/site-packages/mahotas/tests/test_citation.py .                                                                                                                                               [  4%]
.local/lib/python3.8/site-packages/mahotas/tests/test_close_holes.py .                                                                                                                                            [  4%]
.local/lib/python3.8/site-packages/mahotas/tests/test_colors.py ...                                                                                                                                               [  5%]
.local/lib/python3.8/site-packages/mahotas/tests/test_convolve.py .........................                                                                                                                       [ 14%]
.local/lib/python3.8/site-packages/mahotas/tests/test_demos.py .                                                                                                                                                  [ 14%]
.local/lib/python3.8/site-packages/mahotas/tests/test_dilate_erode.py ...........                                                                                                                                 [ 17%]
.local/lib/python3.8/site-packages/mahotas/tests/test_distance.py ...                                                                                                                                             [ 18%]
.local/lib/python3.8/site-packages/mahotas/tests/test_edge.py .......                                                                                                                                             [ 21%]
.local/lib/python3.8/site-packages/mahotas/tests/test_euler.py ...                                                                                                                                                [ 22%]
.local/lib/python3.8/site-packages/mahotas/tests/test_features_shape.py ....                                                                                                                                      [ 23%]
.local/lib/python3.8/site-packages/mahotas/tests/test_filters.py ...                                                                                                                                              [ 24%]
.local/lib/python3.8/site-packages/mahotas/tests/test_find.py ..                                                                                                                                                  [ 25%]
.local/lib/python3.8/site-packages/mahotas/tests/test_freeimage.py ssssssss                                                                                                                                       [ 27%]
.local/lib/python3.8/site-packages/mahotas/tests/test_gvoronoi.py ..                                                                                                                                              [ 28%]
.local/lib/python3.8/site-packages/mahotas/tests/test_histogram.py .....                                                                                                                                          [ 29%]
.local/lib/python3.8/site-packages/mahotas/tests/test_hitmiss.py ...                                                                                                                                              [ 30%]
.local/lib/python3.8/site-packages/mahotas/tests/test_imresize.py ...                                                                                                                                             [ 31%]
.local/lib/python3.8/site-packages/mahotas/tests/test_internal.py .............................                                                                                                                   [ 41%]
.local/lib/python3.8/site-packages/mahotas/tests/test_interpolate.py .............                                                                                                                                [ 45%]
.local/lib/python3.8/site-packages/mahotas/tests/test_io.py ....                                                                                                                                                  [ 46%]
.local/lib/python3.8/site-packages/mahotas/tests/test_label.py ...                                                                                                                                                [ 47%]
.local/lib/python3.8/site-packages/mahotas/tests/test_labeled.py ...................                                                                                                                              [ 54%]
.local/lib/python3.8/site-packages/mahotas/tests/test_lbp.py ..........                                                                                                                                           [ 57%]
.local/lib/python3.8/site-packages/mahotas/tests/test_mahotas.py .                                                                                                                                                [ 57%]
.local/lib/python3.8/site-packages/mahotas/tests/test_majority.py ......                                                                                                                                          [ 59%]
.local/lib/python3.8/site-packages/mahotas/tests/test_mean_filter.py .                                                                                                                                            [ 59%]
.local/lib/python3.8/site-packages/mahotas/tests/test_median_filter.py ....                                                                                                                                       [ 61%]
.local/lib/python3.8/site-packages/mahotas/tests/test_moments.py .........                                                                                                                                        [ 64%]
.local/lib/python3.8/site-packages/mahotas/tests/test_morph.py .............                                                                                                                                      [ 68%]
.local/lib/python3.8/site-packages/mahotas/tests/test_polygon.py .........                                                                                                                                        [ 71%]
.local/lib/python3.8/site-packages/mahotas/tests/test_segmentation.py .                                                                                                                                           [ 71%]
.local/lib/python3.8/site-packages/mahotas/tests/test_stretch.py .........                                                                                                                                        [ 74%]
.local/lib/python3.8/site-packages/mahotas/tests/test_surf.py ..............                                                                                                                                      [ 79%]
.local/lib/python3.8/site-packages/mahotas/tests/test_surf_regression.py ..                                                                                                                                       [ 79%]
.local/lib/python3.8/site-packages/mahotas/tests/test_tas.py .....                                                                                                                                                [ 81%]
.local/lib/python3.8/site-packages/mahotas/tests/test_template_match.py .                                                                                                                                         [ 81%]
.local/lib/python3.8/site-packages/mahotas/tests/test_texture.py ....................                                                                                                                             [ 88%]
.local/lib/python3.8/site-packages/mahotas/tests/test_thin.py .....                                                                                                                                               [ 89%]
.local/lib/python3.8/site-packages/mahotas/tests/test_thresholding.py ..........                                                                                                                                  [ 93%]
.local/lib/python3.8/site-packages/mahotas/tests/test_watershed.py ..................                                                                                                                             [ 99%]
.local/lib/python3.8/site-packages/mahotas/tests/test_zernike.py ...                                                                                                                                              [100%]

=================================================================================================== warnings summary ====================================================================================================
.local/lib/python3.8/site-packages/mahotas/tests/test_convolve.py::test_center_decenter
.local/lib/python3.8/site-packages/mahotas/tests/test_convolve.py::test_center_border
.local/lib/python3.8/site-packages/mahotas/tests/test_convolve.py::test_center_wavelet_iwavelet_decenter
  /home/ubuntu/.local/lib/python3.8/site-packages/mahotas/convolve.py:479: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
    nimage[position] = f

.local/lib/python3.8/site-packages/mahotas/tests/test_convolve.py::test_center_decenter
.local/lib/python3.8/site-packages/mahotas/tests/test_convolve.py::test_center_wavelet_iwavelet_decenter
  /home/ubuntu/.local/lib/python3.8/site-packages/mahotas/convolve.py:510: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
    return w[position]

-- Docs: https://docs.pytest.org/en/stable/warnings.html
====================================================================================== 299 passed, 8 skipped, 5 warnings in 14.20s ======================================================================================
<ExitCode.OK: 0>
luispedro commented 4 years ago

Thanks for the test outputs. I think from mahotas' POV, everything is working so I am closing here