import langchain => Error : TypeError: issubclass() arg 1 must be a class
Asked Answered
A

7

35

I want to use langchain for my project.

so I installed it using following command : pip install langchain

but While importing "langchain" I am facing following Error:

File /usr/lib/python3.8/typing.py:774, in _GenericAlias.__subclasscheck__(self, cls)
    772 if self._special:
    773     if not isinstance(cls, _GenericAlias):
--> 774         return issubclass(cls, self.__origin__)
    775     if cls._special:
    776         return issubclass(cls.__origin__, self.__origin__)

TypeError: issubclass() arg 1 must be a class

Any one who can solve this error ?

Autism answered 23/5, 2023 at 10:9 Comment(1)
Please show the relevant code and full traceback (not only the last line). But first guess: make sure your own files don't have names colliding with names from the libsScrivens
P
22
typing-inspect==0.8.0
typing_extensions==4.5.0
Plenipotentiary answered 23/5, 2023 at 11:55 Comment(4)
We were successful just pinning typing_extensions to 4.5.0. Then again we don't include typing-inspect so YMMVMcintyre
This leads to ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. langchain 0.0.162 requires pydantic<2,>=1, which is not installed. apache-beam 2.49.0 requires protobuf<4.24.0,>=3.20.3, but you have protobuf 3.19.6 which is incompatible. pydantic-core 2.4.0 requires typing-extensions!=4.7.0,>=4.6.0, but you have typing-extensions 4.5.0 which is incompatible. torchaudio 0.12.0 requires torch==1.12.0, but you have torch 1.12.1 which is incompatible.Flack
Your answer would be better if you give the whole command (pip install ...) and more context informationGodson
Too terse to be usable...Couvade
B
28

So I was trying it for hours and at last I found a solution hope it helps you.

First, I did this:

pip install typing-inspect==0.8.0 typing_extensions==4.5.0

Then:

pip install pydantic -U

After this will throw an error but once again I did:

pip install pydantic==1.10.11

Then it started working.

Bister answered 12/7, 2023 at 12:9 Comment(5)
Same. It worked after it.Hacker
Where did you insert the following line 'typing-inspect==0.8.0 typing_extensions==4.5.0'. Did you use it as an environment variable?Kakapo
You do need pip install pydantic -U, directly use pip install pydantic==1.10.11. @Kakapo this needs to be run using pip install like pip install typing-inspect==0.8.0 typing_extensions==4.5.0Staircase
This solution worked for me.Highflier
Thanks it worked for me. But I would like to know the reason behind this.Vesica
P
22
typing-inspect==0.8.0
typing_extensions==4.5.0
Plenipotentiary answered 23/5, 2023 at 11:55 Comment(4)
We were successful just pinning typing_extensions to 4.5.0. Then again we don't include typing-inspect so YMMVMcintyre
This leads to ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. langchain 0.0.162 requires pydantic<2,>=1, which is not installed. apache-beam 2.49.0 requires protobuf<4.24.0,>=3.20.3, but you have protobuf 3.19.6 which is incompatible. pydantic-core 2.4.0 requires typing-extensions!=4.7.0,>=4.6.0, but you have typing-extensions 4.5.0 which is incompatible. torchaudio 0.12.0 requires torch==1.12.0, but you have torch 1.12.1 which is incompatible.Flack
Your answer would be better if you give the whole command (pip install ...) and more context informationGodson
Too terse to be usable...Couvade
U
15

After installing so many packages got a solution using below package

!pip install pydantic -U
Ulrich answered 16/6, 2023 at 11:41 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Alake
worked here too! had this issue just when importing the csvloader class, and the above typing_extensions did notPink
B
5

Fixed in Pydantic 1.10.8. For poetry, use pydantic = "^1.10.8" in your pyproject.toml file.

Billyebilobate answered 29/5, 2023 at 18:47 Comment(0)
S
2

Install langchain version 0.0.133. After this version, the error occurs.

Synergism answered 23/5, 2023 at 10:56 Comment(1)
ImportError: cannot import name 'SUFFIX' from 'langchain.agents.agent_toolkits.pandas.prompt' (/home/konsultera/Downloads/private_chat_gpt/chatgpt_env/lib/python3.8/site-packages/langchain/agents/agent_toolkits/pandas/prompt.py) ---> got this Error for the version u have suggested.Autism
P
0

For me the issue got resolved after I changed my Python version - the error was happening on an environment using Python 3.9, I then switched to another environment using Python 3.11 and the issue got resolved.

Probate answered 6/2 at 6:33 Comment(0)
P
-6

The error message suggests that there is an issue with the typing module in Python. It seems that the subclass() function is being called with an argument that is not a class.

To solve this error, you can try updating the typing module to the latest version. You can do this by running the following command:

pip install 

If the issue persists, you can also try reinstalling the langchain package:

pip uninstall langchain
pip install langchain

If none of these solutions work, it is possible that there is a compatibility issue between the langchain package and your Python version. In that case, you may need to use a different version of Python or contact the package maintainers for further assistance.

Peng answered 1/7, 2023 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.