https://prefect.io logo
j

JoyceC

08/04/2023, 7:56 PM
Hello, I am having trouble importing prefect flow and task in a databricks notebook.
from prefect import flow, task, Parameter
First error was "ImportError: cannot import name 'deprecated' from 'typing_extensions'" when I was using python 3.10. I changed the version to 3.8 and now getting "ImportError: cannot import name 'TypeGuard' from 'typing_extensions' (/databricks/python/lib/python3.8/site-packages/typing_extensions.py)" Here's the full error log. How can I resolve this?
Copy code
ImportError                               Traceback (most recent call last)
<command-1880743847103486> in <module>
      1 from typing import Any, Awaitable, Dict, List, Optional, Union
----> 2 from prefect import flow, task
      3 from prefect import Parameter
      4 from typing import Any
      5 from datetime import timedelta

/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
    165             # Import the desired module. If you're seeing this while debugging a failed import,
    166             # look at preceding stack frames for relevant error information.
--> 167             original_result = python_builtin_import(name, globals, locals, fromlist, level)
    168 
    169             is_root_import = thread_local._nest_level == 1

/databricks/python/lib/python3.8/site-packages/prefect/__init__.py in <module>
     35 
     36 # Import user-facing API
---> 37 from prefect.states import State
     38 from prefect.logging import get_run_logger
     39 from prefect.flows import flow, Flow

/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
    165             # Import the desired module. If you're seeing this while debugging a failed import,
    166             # look at preceding stack frames for relevant error information.
--> 167             original_result = python_builtin_import(name, globals, locals, fromlist, level)
    168 
    169             is_root_import = thread_local._nest_level == 1

/databricks/python/lib/python3.8/site-packages/prefect/states.py in <module>
     10 import httpx
     11 import pendulum
---> 12 from typing_extensions import TypeGuard
     13 
     14 from prefect.client.schemas import State as State

ImportError: cannot import name 'TypeGuard' from 'typing_extensions' (/databricks/python/lib/python3.8/site-packages/typing_extensions.py)
n

Nate

08/04/2023, 8:35 PM
hi @JoyceC - what version of prefect are you on?
j

JoyceC

08/04/2023, 9:00 PM
Hi @Nate, I'm using prefect 2.11.1
I have tried it both with prefect 2.9.0 and 2.11.1 and still getting the
ImportError: cannot import name 'TypeGuard' from 'typing_extensions' (/databricks/python/lib/python3.8/site-packages/typing_extensions.py)
j

Jake Kaplan

08/04/2023, 10:04 PM
can you try and update typing extensions? https://stackoverflow.com/questions/69174965/cannot-import-name-typeguard-from-typing-extensions I think your notebook env is overwriting the version the version that prefect uses
🙏 1
j

JoyceC

08/05/2023, 1:02 AM
I forgot to mention that I also upgraded the typing-extensions too.
I'm still getting the same error
2 Views