GoogleCloudPlatform / generative-ai

Sample code and notebooks for Generative AI on Google Cloud, with Gemini on Vertex AI
https://cloud.google.com/vertex-ai/docs/generative-ai/learn/overview
Apache License 2.0
6.34k stars 1.65k forks source link

[Bug]: AttributeError: module 'shapely' has no attribute 'strtree' #849

Closed sandboxcode closed 23 hours ago

sandboxcode commented 1 week ago

File Name

intro_prompt_design.ipynb

What happened?

When running the "Import libraries" code cell with the correct project ID and region. I get the following error.

Relevant log output

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 1
----> 1 import vertexai
      3 PROJECT_ID = "qwiklabs-gcp-02-857ce462e157"  # @param {type:"string"}
      4 REGION = "us-central1"  # @param {type:"string"}

File /opt/conda/lib/python3.10/site-packages/vertexai/__init__.py:19
     15 """The vertexai module."""
     17 import importlib
---> 19 from google.cloud.aiplatform import version as aiplatform_version
     21 __version__ = aiplatform_version.__version__
     23 from google.cloud.aiplatform import init

File /opt/conda/lib/python3.10/site-packages/google/cloud/aiplatform/__init__.py:26
     21 __version__ = aiplatform_version.__version__
     24 from google.cloud.aiplatform import initializer
---> 26 from google.cloud.aiplatform.datasets import (
     27     ImageDataset,
     28     TabularDataset,
     29     TextDataset,
     30     TimeSeriesDataset,
     31     VideoDataset,
     32 )
     33 from google.cloud.aiplatform import explain
     34 from google.cloud.aiplatform import gapic

File /opt/conda/lib/python3.10/site-packages/google/cloud/aiplatform/datasets/__init__.py:19
      1 # -*- coding: utf-8 -*-
      2 
      3 # Copyright 2020 Google LLC
   (...)
     15 # limitations under the License.
     16 #
     18 from google.cloud.aiplatform.datasets.dataset import _Dataset
---> 19 from google.cloud.aiplatform.datasets.column_names_dataset import _ColumnNamesDataset
     20 from google.cloud.aiplatform.datasets.tabular_dataset import TabularDataset
     21 from google.cloud.aiplatform.datasets.time_series_dataset import TimeSeriesDataset

File /opt/conda/lib/python3.10/site-packages/google/cloud/aiplatform/datasets/column_names_dataset.py:24
     21 from typing import List, Optional, Set
     22 from google.auth import credentials as auth_credentials
---> 24 from google.cloud import bigquery
     25 from google.cloud import storage
     27 from google.cloud.aiplatform import utils

File ~/.local/lib/python3.10/site-packages/google/cloud/bigquery/__init__.py:35
     31 from google.cloud.bigquery import version as bigquery_version
     33 __version__ = bigquery_version.__version__
---> 35 from google.cloud.bigquery.client import Client
     36 from google.cloud.bigquery.dataset import AccessEntry
     37 from google.cloud.bigquery.dataset import Dataset

File ~/.local/lib/python3.10/site-packages/google/cloud/bigquery/client.py:75
     73 from google.cloud.bigquery._http import Connection
     74 from google.cloud.bigquery import _pandas_helpers
---> 75 from google.cloud.bigquery.dataset import Dataset
     76 from google.cloud.bigquery.dataset import DatasetListItem
     77 from google.cloud.bigquery.dataset import DatasetReference

File ~/.local/lib/python3.10/site-packages/google/cloud/bigquery/dataset.py:25
     23 from google.cloud.bigquery import _helpers
     24 from google.cloud.bigquery.model import ModelReference
---> 25 from google.cloud.bigquery.routine import RoutineReference
     26 from google.cloud.bigquery.table import TableReference
     27 from google.cloud.bigquery.encryption_configuration import EncryptionConfiguration

File ~/.local/lib/python3.10/site-packages/google/cloud/bigquery/routine/__init__.py:18
      1 # Copyright 2021 Google LLC
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
   (...)
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     15 """User-Defined Routines."""
---> 18 from google.cloud.bigquery.enums import DeterminismLevel
     19 from google.cloud.bigquery.routine.routine import Routine
     20 from google.cloud.bigquery.routine.routine import RoutineArgument

File ~/.local/lib/python3.10/site-packages/google/cloud/bigquery/enums.py:21
     18 import itertools
     20 from google.cloud.bigquery_v2 import types as gapic_types
---> 21 from google.cloud.bigquery.query import ScalarQueryParameterType
     24 class AutoRowIDs(enum.Enum):
     25     """How to handle automatic insert IDs when inserting rows as a stream."""

File ~/.local/lib/python3.10/site-packages/google/cloud/bigquery/query.py:23
     20 import decimal
     21 from typing import Any, Optional, Dict, Union
---> 23 from google.cloud.bigquery.table import _parse_schema_resource
     24 from google.cloud.bigquery._helpers import _rows_from_json
     25 from google.cloud.bigquery._helpers import _QUERY_PARAMS_FROM_JSON

File ~/.local/lib/python3.10/site-packages/google/cloud/bigquery/table.py:33
     30     pandas = None
     32 try:
---> 33     import geopandas  # type: ignore
     34 except ImportError:
     35     geopandas = None

File /opt/conda/lib/python3.10/site-packages/geopandas/__init__.py:3
      1 from geopandas._config import options
----> 3 from geopandas.geoseries import GeoSeries
      4 from geopandas.geodataframe import GeoDataFrame
      5 from geopandas.array import points_from_xy

File /opt/conda/lib/python3.10/site-packages/geopandas/geoseries.py:18
     15 from shapely.geometry.base import BaseGeometry
     17 import geopandas
---> 18 from geopandas.base import GeoPandasBase, _delegate_property
     19 from geopandas.explore import _explore_geoseries
     20 from geopandas.plotting import plot_series

File /opt/conda/lib/python3.10/site-packages/geopandas/base.py:13
     10 from shapely.geometry.base import BaseGeometry
     12 from . import _compat as compat
---> 13 from .array import GeometryArray, GeometryDtype, points_from_xy
     16 def is_geometry_type(data):
     17     """
     18     Check if the data is of geometry dtype.
     19 
     20     Does not include object array of shapely scalars.
     21     """

File /opt/conda/lib/python3.10/site-packages/geopandas/array.py:23
     20 from shapely.geometry.base import BaseGeometry
     22 from ._compat import HAS_PYPROJ, requires_pyproj
---> 23 from .sindex import SpatialIndex
     25 if HAS_PYPROJ:
     26     from pyproj import Transformer

File /opt/conda/lib/python3.10/site-packages/geopandas/sindex.py:9
      6 from . import _compat as compat
      7 from . import array, geoseries
----> 9 PREDICATES = {p.name for p in shapely.strtree.BinaryPredicate} | {None}
     11 if compat.GEOS_GE_310:
     12     PREDICATES.update(["dwithin"])

AttributeError: module 'shapely' has no attribute 'strtree'

Code of Conduct

sandboxcode commented 1 week ago

I was able to run it using the following cell:

!pip uninstall -y shapely pygeos geopandas
# Install specific versions of shapely, pygeos, and geopandas known to be compatible
!pip install shapely==1.8.5.post1 pygeos==0.12.0 geopandas==0.10.2
# Upgrade google-cloud-aiplatform
!pip install -U google-cloud-aiplatform

@ Google-Team please add to / edit the Repo.

AashisAashu commented 1 week ago

Thanks for your code . I am able to run the file

I was able to run it using the following cell:

!pip uninstall -y shapely pygeos geopandas
# Install specific versions of shapely, pygeos, and geopandas known to be compatible
!pip install shapely==1.8.5.post1 pygeos==0.12.0 geopandas==0.10.2
# Upgrade google-cloud-aiplatform
!pip install -U google-cloud-aiplatform

@ Google-Team please add to / edit the Repo.

holtskinner commented 23 hours ago

This was fixed in the Vertex AI SDK. I updated the notebook to upgrade to the latest version of the SDK.