langchain: import langchain with python<=3.9 fails
System Info
- platform
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
- python
$ python -V
Python 3.9.7
# installed with
asdf install python 3.9.7
- problematic dependency (updated after this comment)
# this was updated today.
typing_extensions==4.6.0
- dependencies
langchain==0.0.177
openapi-schema-pydantic==1.2.4
pydantic==1.10.7
all the dependencies
$ pip install langchain
Collecting langchain
Using cached langchain-0.0.177-py3-none-any.whl (877 kB)
Collecting PyYAML>=5.4.1
Using cached PyYAML-6.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (661 kB)
Collecting openapi-schema-pydantic<2.0,>=1.2
Using cached openapi_schema_pydantic-1.2.4-py3-none-any.whl (90 kB)
Collecting requests<3,>=2
Using cached requests-2.31.0-py3-none-any.whl (62 kB)
Collecting SQLAlchemy<3,>=1.4
Using cached SQLAlchemy-2.0.15-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB)
Collecting aiohttp<4.0.0,>=3.8.3
Using cached aiohttp-3.8.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB)
Collecting dataclasses-json<0.6.0,>=0.5.7
Using cached dataclasses_json-0.5.7-py3-none-any.whl (25 kB)
Collecting async-timeout<5.0.0,>=4.0.0
Using cached async_timeout-4.0.2-py3-none-any.whl (5.8 kB)
Collecting numexpr<3.0.0,>=2.8.4
Using cached numexpr-2.8.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (380 kB)
Collecting pydantic<2,>=1
Using cached pydantic-1.10.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB)
Collecting numpy<2,>=1
Using cached numpy-1.24.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
Collecting tenacity<9.0.0,>=8.1.0
Using cached tenacity-8.2.2-py3-none-any.whl (24 kB)
Collecting multidict<7.0,>=4.5
Using cached multidict-6.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (114 kB)
Collecting attrs>=17.3.0
Using cached attrs-23.1.0-py3-none-any.whl (61 kB)
Collecting charset-normalizer<4.0,>=2.0
Using cached charset_normalizer-3.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199 kB)
Collecting yarl<2.0,>=1.0
Using cached yarl-1.9.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (269 kB)
Collecting frozenlist>=1.1.1
Using cached frozenlist-1.3.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158 kB)
Collecting aiosignal>=1.1.2
Using cached aiosignal-1.3.1-py3-none-any.whl (7.6 kB)
Collecting typing-inspect>=0.4.0
Using cached typing_inspect-0.8.0-py3-none-any.whl (8.7 kB)
Collecting marshmallow<4.0.0,>=3.3.0
Using cached marshmallow-3.19.0-py3-none-any.whl (49 kB)
Collecting marshmallow-enum<2.0.0,>=1.5.1
Using cached marshmallow_enum-1.5.1-py2.py3-none-any.whl (4.2 kB)
Collecting packaging>=17.0
Using cached packaging-23.1-py3-none-any.whl (48 kB)
Collecting typing-extensions>=4.2.0
Using cached typing_extensions-4.6.0-py3-none-any.whl (30 kB)
Collecting idna<4,>=2.5
Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting urllib3<3,>=1.21.1
Using cached urllib3-2.0.2-py3-none-any.whl (123 kB)
Collecting certifi>=2017.4.17
Using cached certifi-2023.5.7-py3-none-any.whl (156 kB)
Collecting greenlet!=0.4.17
Using cached greenlet-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (610 kB)
Collecting mypy-extensions>=0.3.0
Using cached mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)
Installing collected packages: packaging, typing-extensions, mypy-extensions, multidict, marshmallow, idna, frozenlist, yarl, urllib3, typing-inspect, pydantic, numpy, marshmallow-enum, greenlet, charset-normalizer, certifi, attrs, async-timeout, aiosignal, tenacity, SQLAlchemy, requests, PyYAML, openapi-schema-pydantic, numexpr, dataclasses-json, aiohttp, langchain
Successfully installed PyYAML-6.0 SQLAlchemy-2.0.15 aiohttp-3.8.4 aiosignal-1.3.1 async-timeout-4.0.2 attrs-23.1.0 certifi-2023.5.7 charset-normalizer-3.1.0 dataclasses-json-0.5.7 frozenlist-1.3.3 greenlet-2.0.2 idna-3.4 langchain-0.0.177 marshmallow-3.19.0 marshmallow-enum-1.5.1 multidict-6.0.4 mypy-extensions-1.0.0 numexpr-2.8.4 numpy-1.24.3 openapi-schema-pydantic-1.2.4 packaging-23.1 pydantic-1.10.7 requests-2.31.0 tenacity-8.2.2 typing-extensions-4.6.0 typing-inspect-0.8.0 urllib3-2.0.2 yarl-1.9.2
Who can help?
Information
- The official example notebooks/scripts
- My own modified scripts
Related Components
- LLMs/Chat Models
- Embedding Models
- Prompts / Prompt Templates / Prompt Selectors
- Output Parsers
- Document Loaders
- Vector Stores / Retrievers
- Memory
- Agents / Agent Executors
- Tools / Toolkits
- Chains
- Callbacks/Tracing
- Async
Reproduction
- install python==3.9.7 or 3.9.8 or 3.9.9 (with asdf or docker. I didn’t checked the other versions.)
- install langchain
pip install langchain
- see the error
Python 3.9.7 (default, May 23 2023, 11:05:54)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import langchain
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/__init__.py", line 6, in <module>
from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/agents/__init__.py", line 2, in <module>
from langchain.agents.agent import (
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/agents/agent.py", line 16, in <module>
from langchain.agents.tools import InvalidTool
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/agents/tools.py", line 8, in <module>
from langchain.tools.base import BaseTool, Tool, tool
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/tools/__init__.py", line 42, in <module>
from langchain.tools.vectorstore.tool import (
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/tools/vectorstore/tool.py", line 13, in <module>
from langchain.chains import RetrievalQA, RetrievalQAWithSourcesChain
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/chains/__init__.py", line 2, in <module>
from langchain.chains.api.base import APIChain
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/chains/api/base.py", line 13, in <module>
from langchain.chains.api.prompt import API_RESPONSE_PROMPT, API_URL_PROMPT
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/chains/api/prompt.py", line 2, in <module>
from langchain.prompts.prompt import PromptTemplate
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/prompts/__init__.py", line 3, in <module>
from langchain.prompts.chat import (
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/prompts/chat.py", line 10, in <module>
from langchain.memory.buffer import get_buffer_string
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/memory/__init__.py", line 28, in <module>
from langchain.memory.vectorstore import VectorStoreRetrieverMemory
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/memory/vectorstore.py", line 10, in <module>
from langchain.vectorstores.base import VectorStoreRetriever
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/vectorstores/__init__.py", line 2, in <module>
from langchain.vectorstores.analyticdb import AnalyticDB
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/vectorstores/analyticdb.py", line 16, in <module>
from langchain.embeddings.base import Embeddings
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/embeddings/__init__.py", line 19, in <module>
from langchain.embeddings.openai import OpenAIEmbeddings
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/site-packages/langchain/embeddings/openai.py", line 67, in <module>
class OpenAIEmbeddings(BaseModel, Embeddings):
File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
File "pydantic/fields.py", line 663, in pydantic.fields.ModelField._type_analysis
File "pydantic/fields.py", line 808, in pydantic.fields.ModelField._create_sub_type
File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
File "pydantic/fields.py", line 668, in pydantic.fields.ModelField._type_analysis
File "/home/takumi/.asdf/installs/python/3.9.7/lib/python3.9/typing.py", line 847, in __subclasscheck__
return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class
>>>
with docker
$ docker run -it python:3.9.7-bullseye bash
$ pip install langchain
$ python -c "import langchain"
Expected behavior
Python 3.10.1 (main, Dec 21 2021, 09:01:08) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import langchain
>>>
-
what to do?
- ~change python dependency to 3.10 or later~
- fix the version of typing_extensions to 4.5.0 or change the relevant code.
-
Thank you for checking out this issue. If there are anything more to check, I would be glad to help.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 10
- Comments: 31 (3 by maintainers)
Commits related to this issue
- force typing extension version because of https://github.com/hwchase17/langchain/issues/5113 — committed to Chainlit/chainlit by willydouhard a year ago
Fix version of these dependence:
Solve the issue for me:
It worked! Thank you!
typing_extensions was updated only a few hours ago and it seems to have caused something. https://pypi.org/project/typing-extensions/#history
fixed the issue with pydantic==1.10.8
Thanks !
pip install pydantic==1.10.8
works for meHmm it’s not working for me. I had tried to uninstall both packages and langchain and then reinstall them as well. Any other pointers?
Running in to this for python v3.8 and v3.9
I suspect some package that has not been pinned has been updated in the past few hours on pypi
can confirm that on my side, running this command fixed the problem
pip install typing-inspect==0.8.0 typing_extensions==4.5.0
Latest pydantic==1.10.8 fixed this issue in here. Langchain needs no update because pydantic dependency is > 1 in here.
Just in case, this is how to check the update.
BTW it also fails with
typing_extensions==4.6.0
.TY - I thought I was losing my mind. Was working on my laptop but not my GCP instance. This fixed it.
Spent hours debugging this. Glad I found this thread. python:3.10-slim worked for me. Thanks @tiensunguyen
In Dockerfile, FROM python:3.10-slim is ok for me.
I encountered the same error while using langchain on Docker.
Here’s my Dockerfile:
I didn’t face this issue on my local Ubuntu as below with python-3.8.
I modified requirements.txt by changing
langchain==0.0.173
tolangchain==0.0.125
, and it worked.The pypi says ">Python >=3.8.1, <4.0 " https://pypi.org/project/langchain/#description
I get the same error on py3.9 too. and on Python 3.10.6, it is ok.