issubclass() arg 1 TypeError when importing langchain_openai

Hi I’m working inside Jupyter Notebook.

I run into the following errors when I tried to run
from langchain_openai import ChatOpenAI

The notebook ran successfully on another computer so I’m not sure if some dependencies got messed up.

TypeError                                 Traceback (most recent call last)
Input In [8], in <cell line: 10>()
      8 from urllib.parse import urlparse
      9 from tqdm.notebook import tqdm
---> 10 from langchain_openai import ChatOpenAI
     11 from langchain.schema import HumanMessage, SystemMessage, AIMessage
     13 blocked_sites = []

File ~AppDataRoamingPythonPython39site-packageslangchain_openai__init__.py:1, in <module>
----> 1 from langchain_openai.chat_models import AzureChatOpenAI, ChatOpenAI
      2 from langchain_openai.embeddings import AzureOpenAIEmbeddings, OpenAIEmbeddings
      3 from langchain_openai.llms import AzureOpenAI, OpenAI

File ~AppDataRoamingPythonPython39site-packageslangchain_openaichat_models__init__.py:1, in <module>
----> 1 from langchain_openai.chat_models.azure import AzureChatOpenAI
      2 from langchain_openai.chat_models.base import ChatOpenAI
      4 __all__ = ["ChatOpenAI", "AzureChatOpenAI"]

File ~AppDataRoamingPythonPython39site-packageslangchain_openaichat_modelsazure.py:24, in <module>
      8 from typing import (
      9     Any,
     10     Callable,
   (...)
     20     overload,
     21 )
     23 import openai
---> 24 from langchain_core.language_models import LanguageModelInput
     25 from langchain_core.language_models.chat_models import LangSmithParams
     26 from langchain_core.messages import BaseMessage

File ~AppDataRoamingPythonPython39site-packageslangchain_corelanguage_models__init__.py:40, in <module>
      1 """**Language Model** is a type of model that can generate text or complete
      2 text prompts.
      3 
   (...)
     37 https://python.langchain.com/v0.2/docs/how_to/custom_llm/
     38 """  # noqa: E501
---> 40 from langchain_core.language_models.base import (
     41     BaseLanguageModel,
     42     LangSmithParams,
     43     LanguageModelInput,
     44     LanguageModelLike,
     45     LanguageModelOutput,
     46     get_tokenizer,
     47 )
     48 from langchain_core.language_models.chat_models import BaseChatModel, SimpleChatModel
     49 from langchain_core.language_models.fake import FakeListLLM, FakeStreamingListLLM

File ~AppDataRoamingPythonPython39site-packageslangchain_corelanguage_modelsbase.py:24, in <module>
     21 from typing_extensions import TypeAlias, TypedDict
     23 from langchain_core._api import deprecated
---> 24 from langchain_core.messages import (
     25     AnyMessage,
     26     BaseMessage,
     27     MessageLikeRepresentation,
     28     get_buffer_string,
     29 )
     30 from langchain_core.prompt_values import PromptValue
     31 from langchain_core.pydantic_v1 import BaseModel, Field, validator

File ~AppDataRoamingPythonPython39site-packageslangchain_coremessages__init__.py:18, in <module>
      1 """**Messages** are objects used in prompts and chat conversations.
      2 
      3 **Class hierarchy:**
   (...)
     15 
     16 """  # noqa: E501
---> 18 from langchain_core.messages.ai import (
     19     AIMessage,
     20     AIMessageChunk,
     21 )
     22 from langchain_core.messages.base import (
     23     BaseMessage,
     24     BaseMessageChunk,
   (...)
     27     messages_to_dict,
     28 )
     29 from langchain_core.messages.chat import ChatMessage, ChatMessageChunk

File ~AppDataRoamingPythonPython39site-packageslangchain_coremessagesai.py:11, in <module>
      4 from typing_extensions import TypedDict
      6 from langchain_core.messages.base import (
      7     BaseMessage,
      8     BaseMessageChunk,
      9     merge_content,
     10 )
---> 11 from langchain_core.messages.tool import (
     12     InvalidToolCall,
     13     ToolCall,
     14     ToolCallChunk,
     15     default_tool_chunk_parser,
     16     default_tool_parser,
     17 )
     18 from langchain_core.messages.tool import (
     19     invalid_tool_call as create_invalid_tool_call,
     20 )
     21 from langchain_core.messages.tool import (
     22     tool_call as create_tool_call,
     23 )

File ~AppDataRoamingPythonPython39site-packageslangchain_coremessagestool.py:10, in <module>
      6 from langchain_core.messages.base import BaseMessage, BaseMessageChunk, merge_content
      7 from langchain_core.utils._merge import merge_dicts, merge_obj
---> 10 class ToolMessage(BaseMessage):
     11     """Message for passing the result of executing a tool back to a model.
     12 
     13     ToolMessages contain the result of a tool invocation. Typically, the result
   (...)
     48     to request multiple tool calls in parallel.
     49     """  # noqa: E501
     51     tool_call_id: str

File ~AppDataRoamingPythonPython39site-packagespydanticmain.py:205, in pydantic.main.ModelMetaclass.__new__()

File ~AppDataRoamingPythonPython39site-packagespydanticfields.py:491, in pydantic.fields.ModelField.infer()

File ~AppDataRoamingPythonPython39site-packagespydanticfields.py:421, in pydantic.fields.ModelField.__init__()

File ~AppDataRoamingPythonPython39site-packagespydanticfields.py:537, in pydantic.fields.ModelField.prepare()

File ~AppDataRoamingPythonPython39site-packagespydanticfields.py:641, in pydantic.fields.ModelField._type_analysis()

File C:ProgramDataAnaconda3libtyping.py:852, in _SpecialGenericAlias.__subclasscheck__(self, cls)
    850     return issubclass(cls.__origin__, self.__origin__)
    851 if not isinstance(cls, _GenericAlias):
--> 852     return issubclass(cls, self.__origin__)
    853 return super().__subclasscheck__(cls)

TypeError: issubclass() arg 1 must be a class```



I've tried to reinstall the following libraries but I still encounter the same error:
`pip install --upgrade --force-reinstall openai langchain pydantic pydantic-core`

I encountered the same TypeError again. 

Hope to get some guidance on this, thank you.

Looks like there are two paths to different libraries. Your openai and other modules are picked up from ~AppDataRoamingPythonPython39site-packages

And the error lib typing is in C:ProgramDataAnaconda3

I would recommend install typing in the env where you are running your code:

pip install typing

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật