gjoseph92 / stackstac

Turn a STAC catalog into a dask-based xarray
https://stackstac.readthedocs.io
MIT License
238 stars 49 forks source link

Issue in working stackstac in google colab #139

Closed Jimut123 closed 2 years ago

Jimut123 commented 2 years ago

On writing this in colab, we are getting a chain of errors,

import stackstac
import pystac_client

URL = "https://earth-search.aws.element84.com/v0"
catalog = pystac_client.Client.open(URL)

stac_items = catalog.search(
    intersects=dict(type="Point", coordinates=[-105.78, 35.79]),
    collections=["sentinel-s2-l2a-cogs"],
    datetime="2020-04-01/2020-05-01"
).get_all_items()

stack = stackstac.stack(stac_items)
print(stack)

Errors:

---------------------------------------------------------------------------

ImportError                               Traceback (most recent call last)

[<ipython-input-3-dae6a92f8a38>](https://localhost:8080/#) in <module>()
     40 """
     41 
---> 42 import stackstac
     43 import pystac
     44 import pystac_client

1 frames

[/usr/local/lib/python3.7/dist-packages/stackstac/rio_reader.py](https://localhost:8080/#) in <module>()
      5 import threading
      6 import weakref
----> 7 from typing import TYPE_CHECKING, Optional, Protocol, Tuple, Type, Union
      8 
      9 import numpy as np

ImportError: cannot import name 'Protocol' from 'typing' (/usr/lib/python3.7/typing.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

On searching stackoverflow, this seems to be a different issue https://stackoverflow.com/questions/54274630/can-not-import-protocol-from-typing

Here is the notebook https://colab.research.google.com/drive/1-RZW3tnNO2sFdl3BoqI-7J0eDzHC79Rs?usp=sharing.

Can you please figure out a way of running this in google colab? I have also tried to install python 3.8 in colab, but nothing works

! sudo apt-get install python3.8 python3.8-dev python3.8-distutils python3.8-venv
gjoseph92 commented 2 years ago

stackstac requires Python 3.8 or greater. However, some very old versions mistakenly didn't specify this, so when you pip install stackstac, that's what you're getting. It's a mistake that you can install it at all in a 3.7 environment, which I'll fix momentarily: https://github.com/gjoseph92/stackstac/issues/140.

Unfortunately I can't help you figure out how to run colab with Python 3.8, but I'm sure there are plenty of resources available to learn about that.

Jimut123 commented 2 years ago

It is working in my laptop, but I wanted to test that on colab. Thank you anyways!