1

I was trying to import some langchain modules in a notebook in Microsoft Fabric like below.

The notebook is using Python 3.10

Step 1: pip install langchain openai --> successful

Step 2:

from langchain.llms import OpenAI
from langchain.llms import AzureOpenAI
from langchain import PromptTemplate
from langchain.chat_models import ChatOpenAI
from langchain.chains import LLMChain

getting the below error:

ImportError: cannot import name 'TypeAliasType' from 'typing_extensions' (/home/trusted-service-user/cluster-env/trident_env/lib/python3.10/site-packages/typing_extensions.py)

I tried updating the typing_extensions module in Python but nothing seems to work.

Can some please help.

Raptor
  • 53,206
  • 45
  • 230
  • 366
Andy
  • 405
  • 1
  • 5
  • 16
  • what is the version of `typing_extensions`? Here is a [similar issue](https://github.com/pydantic/pydantic/discussions/6621) related to the versioning – Raptor Aug 28 '23 at 03:43
  • More info: if your `typing_extensions` version is <= 4.6.0, you cannot import `TypeAliasType`. Works fine for version 4.7.1. [Related issue](https://github.com/python/typing_extensions/issues/159#issuecomment-1631451146) – Raptor Aug 28 '23 at 03:49

1 Answers1

0

I tried the same scenario in my environment, and I got same error while importing.

enter image description here

I followed the suggestion by @anovoselov from this ask and now it is working fine for me.

Try to re-import the typing_extensions from the sys.path before importing the langchain.

import sys
del sys.modules["typing_extensions"]

enter image description here

Rakesh Govindula
  • 5,257
  • 1
  • 2
  • 11