Skip to content

Unable to run "from langchain_openai import ChatOpenAI" #30868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
Akinola92 opened this issue Apr 16, 2025 · 3 comments
Closed
5 tasks done

Unable to run "from langchain_openai import ChatOpenAI" #30868

Akinola92 opened this issue Apr 16, 2025 · 3 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.

Comments

@Akinola92
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Example Code

"from langchain_openai import ChatOpenAI"

Error Message and Stack Trace (if applicable)

ImportError Traceback (most recent call last)
in <cell line: 0>()
----> 1 from langchain_openai import ChatOpenAI

3 frames
/usr/local/lib/python3.11/dist-packages/langchain_openai/init.py in
----> 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
4
5 all = [

/usr/local/lib/python3.11/dist-packages/langchain_openai/chat_models/init.py in
----> 1 from langchain_openai.chat_models.azure import AzureChatOpenAI
2 from langchain_openai.chat_models.base import ChatOpenAI
3
4 all = ["ChatOpenAI", "AzureChatOpenAI"]

/usr/local/lib/python3.11/dist-packages/langchain_openai/chat_models/azure.py in
10 import openai
11 from langchain_core.language_models import LanguageModelInput
---> 12 from langchain_core.language_models.chat_models import LangSmithParams
13 from langchain_core.messages import BaseMessage
14 from langchain_core.outputs import ChatResult

/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/chat_models.py in
47 )
48 from langchain_core.load import dumpd, dumps
---> 49 from langchain_core.messages import (
50 AIMessage,
51 AnyMessage,

ImportError: cannot import name 'convert_to_openai_image_block' from 'langchain_core.messages' (/usr/local/lib/python3.11/dist-packages/langchain_core/messages/init.py)

Description

Up until a few days ago I was able to run the line "from langchain_openai import ChatOpenAI" in my Google Colab notebook but now I'm receiving the error message "ImportError: cannot import name 'convert_to_openai_image_block' from 'langchain_core.messages' (/usr/local/lib/python3.11/dist-packages/langchain_core/messages/init.py)"

Any ideas on what's going wrong and how I can fix it?

System Info

System Information

OS: Linux
OS Version: #1 SMP PREEMPT_DYNAMIC Thu Jun 27 21:05:47 UTC 2024
Python Version: 3.11.12 (main, Apr 9 2025, 08:55:54) [GCC 11.4.0]

Package Information

langchain_core: 0.3.52
langchain: 0.3.23
langchain_community: 0.3.21
langsmith: 0.3.28
langchain_openai: 0.3.13
langchain_text_splitters: 0.3.8
langgraph_sdk: 0.1.61

Optional packages not installed

langserve

Other Dependencies

aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
dataclasses-json<0.7,>=0.5.7: Installed. No version info available.
httpx: 0.28.1
httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
jsonpatch<2.0,>=1.33: Installed. No version info available.
langchain-anthropic;: Installed. No version info available.
langchain-aws;: Installed. No version info available.
langchain-azure-ai;: Installed. No version info available.
langchain-cohere;: Installed. No version info available.
langchain-community;: Installed. No version info available.
langchain-core<1.0.0,>=0.3.51: Installed. No version info available.
langchain-core<1.0.0,>=0.3.52: Installed. No version info available.
langchain-deepseek;: Installed. No version info available.
langchain-fireworks;: Installed. No version info available.
langchain-google-genai;: Installed. No version info available.
langchain-google-vertexai;: Installed. No version info available.
langchain-groq;: Installed. No version info available.
langchain-huggingface;: Installed. No version info available.
langchain-mistralai;: Installed. No version info available.
langchain-ollama;: Installed. No version info available.
langchain-openai;: Installed. No version info available.
langchain-perplexity;: Installed. No version info available.
langchain-text-splitters<1.0.0,>=0.3.8: Installed. No version info available.
langchain-together;: Installed. No version info available.
langchain-xai;: Installed. No version info available.
langchain<1.0.0,>=0.3.23: Installed. No version info available.
langsmith-pyo3: Installed. No version info available.
langsmith<0.4,>=0.1.125: Installed. No version info available.
langsmith<0.4,>=0.1.17: Installed. No version info available.
numpy<3,>=1.26.2: Installed. No version info available.
openai-agents: Installed. No version info available.
openai<2.0.0,>=1.68.2: Installed. No version info available.
opentelemetry-api: 1.31.1
opentelemetry-exporter-otlp-proto-http: Installed. No version info available.
opentelemetry-sdk: 1.31.1
orjson: 3.10.16
packaging: 24.2
packaging<25,>=23.2: Installed. No version info available.
pydantic: 2.11.3
pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available.
pydantic<3.0.0,>=2.5.2;: Installed. No version info available.
pydantic<3.0.0,>=2.7.4: Installed. No version info available.
pydantic<3.0.0,>=2.7.4;: Installed. No version info available.
pytest: 8.3.5
PyYAML>=5.3: Installed. No version info available.
requests: 2.32.3
requests-toolbelt: 1.0.0
requests<3,>=2: Installed. No version info available.
rich: 13.9.4
SQLAlchemy<3,>=1.4: Installed. No version info available.
tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available.
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
tiktoken<1,>=0.7: Installed. No version info available.
typing-extensions>=4.7: Installed. No version info available.
zstandard: 0.23.0

@langcarl langcarl bot added the investigate Flagged for investigation. label Apr 16, 2025
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Apr 16, 2025
@sydney-runkle
Copy link
Collaborator

Thanks for the report - hmm, I'm unable to reproduce this issue with the versions you've listed above :(. Looking into this further.

@ccurme
Copy link
Collaborator

ccurme commented Apr 16, 2025

I suspect you are running a version of langchain-core that is lower than the minimum specified by the latest langchain-openai (0.3.52). Can you try:

  • Restarting the kernel
  • pip install --upgrade langchain-openai (should force an update of langchain-core)
  • pip install --upgrade langchain-core

And let me know if that does not resolve the issue?

@Akinola92
Copy link
Author

pip install --upgrade langchain-openai & pip install --upgrade langchain-core

Looks to have solved it - Thanks @ccurme !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.
Projects
None yet
Development

No branches or pull requests

3 participants