bpurinton / PebbleCounts

PebbleCounts: grain-sizing algorithm for gravel-bed river imagery
GNU General Public License v3.0
12 stars 9 forks source link

Many errors installing and running the code.... #13

Closed masspern closed 1 year ago

masspern commented 1 year ago

The installation notes for windows is not working in my sistem (windows 10, no python installed). I keep on having too many errors...

command executed:

1) installed miniconda with "Miniconda3-latest-Windows-x86_64.exe" 2) run conda create --name pebblecounts python=3.6 opencv shapely scikit-image scikit-learn numpy gdal scipy matplotlib tk 3) downloaded and unzipped repository in the pebblecounts env folder 4) run conda activate pebblecounts 5) from manual run python PebbleCounts.py -im example_data\ortho_resolution_1.2mmPerPix.tif -ortho y 6) solved errors (gdal, pillow)... with pip install C:\Users\xxxxx\Downloads\GDAL-2.4.1-cp36-cp36m-win_amd64.whl (downloaded wheel from official site),
conda uninstall pillow --force-remove, and pip install pillow

7) the code runs, but as I specify not to desire another color mask I obtained:

File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\PCfunctions.py", line 219, in clicker
    image_mask = morph.opening(image_mask, footprint=disk(1))
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\lib\site-packages\skimage\morphology\misc.py", line 39, in func_out
    return func(image, selem=selem, *args, **kwargs)
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\lib\site-packages\skimage\morphology\grey.py", line 122, in func_out
    out_temp = func(image, selem, out=out_temp, *args, **kwargs)
TypeError: opening() got an unexpected keyword argument 'footprint'
bpurinton commented 1 year ago

Thanks for the detailed message.

footprint was a new keyword argument introduced to sciki-learn. I updated the codebase on this commit (here) to use that new format.

That makes me think your running an older scikit-image version.

Can you please do the following:

Activate your environment with:

conda activate pebblecounts

Then in the active environment run:

conda update scikit-image

Hopefully that resolves the issue, but let me know if not.

Sorry for all of the issues with installation. I really ought to update this codebase in a significant way to make it easier to run, but I don't have the time right now.

masspern commented 1 year ago

Thank to you! You did a great job! And thank you for the answers!

I tried your commands and I had:

The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:

  - defaults/noarch::imageio==2.9.0=pyhd3eb1b0_0
  - defaults/win-64::matplotlib==3.3.4=py36haa95532_0
  - defaults/win-64::matplotlib-base==3.3.4=py36h49ac443_0
  - defaults/win-64::scikit-image==0.17.2=py36h1e1f486_0
....

## Package Plan ##

  environment location: C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts

  added / updated specs:
    - scikit-image

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    libtiff-4.5.1              |       hd77b12b_0         1.1 MB
    tifffile-2020.10.1         |   py36h8c2d366_2         296 KB
    tiledb-2.3.3               |       h3649cd2_2         2.0 MB
    ------------------------------------------------------------
                                           Total:         3.3 MB

The following NEW packages will be INSTALLED:

  pillow             pkgs/main/win-64::pillow-8.3.1-py36h4fa10fc_0

The following packages will be UPDATED:

  ca-certificates    conda-forge::ca-certificates-2023.7.2~ --> pkgs/main::ca-certificates-2023.08.22-haa95532_0
  certifi            anaconda/noarch::certifi-2020.6.20-py~ --> pkgs/main/win-64::certifi-2021.5.30-py36haa95532_0
  libtiff                                  4.5.0-h8a3f274_0 --> 4.5.1-hd77b12b_0
  tiledb                                   2.2.9-hf7ce2e6_0 --> 2.3.3-h3649cd2_2
  zstd                                     1.4.9-h19a0ad4_0 --> 1.5.5-hd43e919_0

The following packages will be SUPERSEDED by a higher-priority channel:

  tifffile           pkgs/main/noarch::tifffile-2021.3.17-~ --> pkgs/main/win-64::tifffile-2020.10.1-py36h8c2d366_2

Proceed ([y]/n)? y

Downloading and Extracting Packages

Preparing transaction: done
Verifying transaction: done
Executing transaction: done

but running the code python PebbleCounts.py -im example_data\ortho_resolution_1.2mmPerPix.tif -ortho y I get a similar answer....

Non-local means filtering
Bilateral filtering
Black tophat edge detection
Traceback (most recent call last):
  File "PebbleCounts.py", line 425, in <module>
    tophat = morph.black_tophat(GRAY, footprint=disk(1))
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\lib\site-packages\skimage\morphology\misc.py", line 39, in func_out
    return func(image, selem=selem, *args, **kwargs)
TypeError: black_tophat() got an unexpected keyword argument 'footprint'
bpurinton commented 1 year ago

Let's try these steps:

Deactivate the conda environment:

conda deactivate

Delete the entire conda environment and its packages:

conda env remove --name env_name

Re-install the packages in a new environment by running these commands one at a time:

conda create --name pebblecounts python

conda activate pebblecounts

conda install -c conda-forge opencv

conda install shapely scikit-image scikit-learn numpy gdal scipy matplotlib tk

By leaving the version number of python off in the first command, I'm hoping the packages are all installed with their latest versions and conda will handle any conflicts between package versions that might occur. No promises, but hopefully this gets us closer to the solution.

masspern commented 1 year ago

Thanks.

Tried that and I a problem with gdal:

Traceback (most recent call last):
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\Lib\site-packages\osgeo\__init__.py", line 30, in swig_import_helper
    return importlib.import_module(mname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\Lib\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 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 676, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 573, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1233, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ImportError: DLL load failed while importing _gdal: Impossibile trovare il modulo specificato.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\PebbleCounts.py", line 13, in <module>
    import PCfunctions as func
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\PCfunctions.py", line 11, in <module>
    from osgeo import gdal
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\Lib\site-packages\osgeo\__init__.py", line 46, in <module>
    _gdal = swig_import_helper()
            ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\Lib\site-packages\osgeo\__init__.py", line 42, in swig_import_helper
    raise ImportError(traceback_string + '\n' + msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\perna\AppData\Local\miniconda3\envs\pebblecounts\Lib\site-packages\osgeo\__init__.py", line 30, in swig_import_helper
    return importlib.import_module(mname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\Lib\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 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 676, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 573, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1233, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ImportError: DLL load failed while importing _gdal: Impossibile trovare il modulo specificato.

On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH.
If gdalXXX.dll is in the PATH, then set the USE_PATH_FOR_GDAL_PYTHON=YES environment variable
to feed the PATH into os.add_dll_directory().

so I added USE_PATH_FOR_GDAL_PYTHON=YES environment variable and I have the slightly different:

Traceback (most recent call last):
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\Lib\site-packages\osgeo\__init__.py", line 30, in swig_import_helper
    return importlib.import_module(mname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\Lib\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 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 676, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 573, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1233, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ImportError: DLL load failed while importing _gdal: Impossibile trovare il modulo specificato.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\miniconda3\envs\pebblecounts\PebbleCounts.py", line 13, in <module>
    import PCfunctions as func
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\PCfunctions.py", line 11, in <module>
    from osgeo import gdal
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\Lib\site-packages\osgeo\__init__.py", line 46, in <module>
    _gdal = swig_import_helper()
            ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\Lib\site-packages\osgeo\__init__.py", line 43, in swig_import_helper
    return importlib.import_module('_gdal')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxx\AppData\Local\miniconda3\envs\pebblecounts\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_gdal'
masspern commented 1 year ago

Tested the same procedure in Ubuntu and it works. There must be some kind of problems in windows with paths, I guess....

bpurinton commented 1 year ago

Do you have access to an Ubuntu system to run PebbleCounts? Windows often has tricky installation issues -- I would know I spent 10 years on windows laptops :-/ PebbleCounts was actually developed on Windows; but there is no accounting for different people's local laptop environment which can vary widely.

Another thing to test: earlier in your first post on this thread you solved some GDAL errors by installing it from the .whl file. I wonder if you could try to remove gdal from the pebblecounts environment (run conda remove gdal in the active environment), then try to re-install GDAL with pip or with the .whl method (try each perhaps and see what works?)

masspern commented 1 year ago

Finally I've been able to run the code on windows too!!!

I had to download the whl and run:

python -m pip install C:\Users\xxxx\Downloads\GDAL-3.4.3-cp311-cp311-win_amd64.whl

and then also:

pip install opencv-python

Thank you very much!

Massimo