Skip to content

Error when Importing planetary_computer Package #60

Closed

Description

I recently installed the planetary-computer package (v 1.0.0) from conda forge. It seems like this version of planetary-computer doesn't work with the version of pydantic that loads with the package. I am attempting to import it in a python 3.9 environment, but the import fails and I get the following error:

import planetary_computer

ImportError                               Traceback (most recent call last)
Cell In[2], line 9
      7 import numpy as np
      8 import pandas as pd
----> 9 import planetary_computer
     10 import rasterio
     11 import rasterio.features

File ~/envs/aug/lib/python3.9/site-packages/planetary_computer/__init__.py:4
      1 """Planetary Computer Python SDK"""
      2 # flake8:noqa
----> 4 from planetary_computer.sas import (
      5     sign,
      6     sign_inplace,
      7     sign_url,
      8     sign_item,
      9     sign_assets,
     10     sign_asset,
     11     sign_item_collection,
     12 )
     13 from planetary_computer.settings import set_subscription_key
     14 from planetary_computer._adlfs import get_adlfs_filesystem, get_container_client

File ~/envs/aug/lib/python3.9/site-packages/planetary_computer/sas.py:13
     11 import requests.adapters
     12 import packaging.version
---> 13 import pydantic
     14 from pydantic import BaseModel, Field
     15 from pystac import Asset, Item, ItemCollection, STACObjectType, Collection

File ~/envs/aug/lib/python3.9/site-packages/pydantic/__init__.py:13
      3 import pydantic_core
      4 from pydantic_core.core_schema import (
      5     FieldSerializationInfo,
      6     FieldValidationInfo,
   (...)
     10     ValidatorFunctionWrapHandler,
     11 )
---> 13 from . import dataclasses
     14 from ._internal._annotated_handlers import (
     15     GetCoreSchemaHandler as GetCoreSchemaHandler,
     16 )
     17 from ._internal._annotated_handlers import (
     18     GetJsonSchemaHandler as GetJsonSchemaHandler,
     19 )

File ~/envs/aug/lib/python3.9/site-packages/pydantic/dataclasses.py:11
      7 from typing import TYPE_CHECKING, Any, Callable, Generic, NoReturn, TypeVar, overload
      9 from typing_extensions import Literal, dataclass_transform
---> 11 from ._internal import _config, _decorators, _typing_extra
     12 from ._internal import _dataclasses as _pydantic_dataclasses
     13 from ._migration import getattr_migration

File ~/envs/aug/lib/python3.9/site-packages/pydantic/_internal/_decorators.py:15
     12 from typing_extensions import Literal, TypeAlias, is_typeddict
     14 from ..errors import PydanticUserError
---> 15 from ..fields import ComputedFieldInfo
     16 from ._core_utils import get_type_ref
     17 from ._internal_dataclass import slots_true

File ~/envs/aug/lib/python3.9/site-packages/pydantic/fields.py:18
     15 from pydantic_core import PydanticUndefined
     16 from typing_extensions import Unpack
---> 18 from . import types
     19 from ._internal import _decorators, _fields, _generics, _internal_dataclass, _repr, _typing_extra, _utils
     20 from .errors import PydanticUserError

File ~/envs/aug/lib/python3.9/site-packages/pydantic/types.py:32
     29 from pydantic_core import CoreSchema, PydanticCustomError, PydanticKnownError, core_schema
     30 from typing_extensions import Annotated, Literal, Protocol, deprecated
---> 32 from ._internal import (
     33     _annotated_handlers,
     34     _fields,
     35     _internal_dataclass,
     36     _known_annotated_metadata,
     37     _utils,
     38     _validators,
     39 )
     40 from ._migration import getattr_migration
     41 from .config import ConfigDict

File ~/envs/aug/lib/python3.9/site-packages/pydantic/_internal/_fields.py:12
      8 from typing import TYPE_CHECKING, Any
     10 from pydantic_core import PydanticUndefined
---> 12 from . import _typing_extra
     13 from ._config import ConfigWrapper
     14 from ._repr import Representation

File ~/envs/aug/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py:13
     10 from types import GetSetDescriptorType
     11 from typing import TYPE_CHECKING, Any, ForwardRef
---> 13 from typing_extensions import Annotated, Final, Literal, TypeAliasType, TypeGuard, get_args, get_origin
     15 if TYPE_CHECKING:
     16     from ._dataclasses import StandardDataclass

ImportError: cannot import name 'TypeAliasType' from 'typing_extensions' (/home/jovyan/.local/lib/python3.9/site-packages/typing_extensions.py)

The package versions that downloaded when I installed planetary computer were:

    package                    |            build
    ---------------------------|-----------------
    annotated-types-0.6.0      |     pyhd8ed1ab_0          17 KB  conda-forge
    planetary-computer-1.0.0   |     pyhd8ed1ab_0          18 KB  conda-forge
    pydantic-2.0.3             |     pyhd8ed1ab_1         245 KB  conda-forge
    pydantic-core-2.3.0        |   py39h9fdd4d6_0         1.3 MB  conda-forge
    python-dotenv-1.0.0        |     pyhd8ed1ab_1          23 KB  conda-forge
    ------------------------------------------------------------

I've tried installing earlier versions of pydantic instead, but I don't know which version is necessary for the missing component of the package. Thank you for your help!

Activity

  1. TomAugspurger commented on Nov 1, 2023

    @TomAugspurger

    Interesting, #59 (released in 1.0) should support pydantic v2.

    A couple of questions:

    1. Can you try with pip in a virtual environment? I just tried and it appears to work:
    python3 -m venv .venv
    . .venv/bin/activate  # assuming you're using bash
    python3 -m pip install planetary-computer
    python3 -c "import planetary_computer"  # no error
    
    1. Can you try manually installing typing-extensions in that conda env? I got 4.8.0 in my environment.
  2. elliesch commented on Nov 1, 2023

    @elliesch
    Author

    Thanks for the reply Tom Augspurger (@TomAugspurger).

    First I tried option 2, but even with a manual install of typing-extensions through conda forge, my conda environment did not recognize that it was there, and I received the same error string.

    To avoid chasing down where condo-forge stored the package, I tried option 1 next. In order to get it to work, I reinitialized the conda environment so all the dependencies would be downloaded through the requirements specified in the pypl version of planetary-computer. It's up and running now with a simple python import. Thanks for your help with that!

  3. elliesch commented on Nov 3, 2023

    @elliesch
    Author

    Tom Augspurger (@TomAugspurger) solved the issue with a pip install instead of a conda install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions