Closed yuanqingye closed 10 months ago
This stack trace comes from pydantic, what pydantic version do you have installed?
pydantic
2.5.0
Are you using databricks? There are known issues with their environment breaking things https://github.com/openai/openai-python/issues/751
Are you using databricks? There are known issues with their environment breaking things #751
No, As far as I know, we didn't use databricks. Actually, I haven't heard of that before.
What version of Anaconda are you on?
What version of Anaconda are you on?
23.1.0
Was able to fix this issue by upgrading to Python 3.11
Was able to fix this issue by upgrading to Python 3.11
First, Thank you very much for point out the way to walk through
If possible, can you show me the reason for this bug?
@rattrayalex @RobertCraigie can you re-open this issue? It's still an unresolved issue - a compatibility issue with Python versions before 3.11 where the pypi.org index promises support from 3.7.1 onwards.
The openai
package works for me on Python 3.8, can you share any more details about your environment?
This is probably an issue with pydantic
or typing_extensions
versions. In the pyproject.toml
, it says one can use
"pydantic>=1.9.0, <3",
"typing-extensions>=4.7, <5",
but I got this same error in an environment with
though not in one with
There were several other differences between the envs, but this might be a start towards narrowing down versions of these libraries that work.
This is probably an issue with
pydantic
ortyping_extensions
versions. In thepyproject.toml
, it says one can use"pydantic>=1.9.0, <3", "typing-extensions>=4.7, <5",
but I got this same error in an environment with
- typing_extensions 4.10.0
- pydantic 2.6.2
though not in one with
- typing_extensions 4.8.0
- pydantic 1.10.13
There were several other differences between the envs, but this might be a start towards narrowing down versions of these libraries that work.
This worked.
I still see this issue :
Python version: 3.11 Pydantic version: 2.7.0 typing-extensions version: 4.11.0
Error : ImportError: cannot import name 'TypeAliasType' from 'typing_extensions' (/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/typing_extensions.py)
I still see this issue :
Python version: 3.11 Pydantic version: 2.7.0 typing-extensions version: 4.11.0
Error :ImportError: cannot import name 'TypeAliasType' from 'typing_extensions' (/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/typing_extensions.py)
Install below version of libraries: pydantic==1.10.11 typing_extensions==4.5.0
I still see this issue :
Python version: 3.11 Pydantic version: 2.7.0 typing-extensions version: 4.11.0
Error :ImportError: cannot import name 'TypeAliasType' from 'typing_extensions' (/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/typing_extensions.py)
Install below version of libraries: pydantic==1.10.11 typing_extensions==4.5.0
Thanks @saurabhtiger, I managed to make it work with pydantic==1.10.11 typing_extensions==4.7.0
since openai latest version have a requirement typing_extensions >= 4.7.0
while importing this libraries: import os from apikey import apikey
import streamlit as st from langchain.llms import OpenAI from langchain.prompts import PromptTemplate from langchain.chains import LLMChain, SequentialChain from langchain.memory import ConversationBufferMemory from langchain.utilities import WikipediaAPIWrapper
ImportError Traceback (most recent call last) Cell In[31], line 9 7 from langchain.prompts import PromptTemplate 8 from langchain.chains import LLMChain, SequentialChain ----> 9 from langchain.memory import ConversationBufferMemory 10 from langchain.utilities import WikipediaAPIWrapper
File ~\anaconda3\lib\site-packages\langchain\memory__init__.py:29 1 """Memory maintains Chain state, incorporating context from past runs. 2 3 Class hierarchy for Memory: (...) 27 AIMessage, BaseMessage, HumanMessage 28 """ # noqa: E501 ---> 29 from langchain_community.chat_message_histories import ( 30 AstraDBChatMessageHistory, 31 CassandraChatMessageHistory, 32 ChatMessageHistory, 33 CosmosDBChatMessageHistory, 34 DynamoDBChatMessageHistory, 35 ElasticsearchChatMessageHistory, 36 FileChatMessageHistory, 37 MomentoChatMessageHistory, 38 MongoDBChatMessageHistory, 39 PostgresChatMessageHistory, 40 RedisChatMessageHistory, 41 SingleStoreDBChatMessageHistory, 42 SQLChatMessageHistory, 43 StreamlitChatMessageHistory, 44 UpstashRedisChatMessageHistory, 45 XataChatMessageHistory, 46 ZepChatMessageHistory, 47 ) 49 from langchain.memory.buffer import ( 50 ConversationBufferMemory, 51 ConversationStringBufferMemory, 52 ) 53 from langchain.memory.buffer_window import ConversationBufferWindowMemory
File ~\anaconda3\lib\site-packages\langchain_community\chat_message_histories__init.py:137, in getattr(name) 135 def getattr__(name: str) -> Any: 136 if name in _module_lookup: --> 137 module = importlib.import_module(_module_lookup[name]) 138 return getattr(module, name) 139 raise AttributeError(f"module {name} has no attribute {name}")
File ~\anaconda3\lib\importlib__init__.py:126, in import_module(name, package) 124 break 125 level += 1 --> 126 return _bootstrap._gcd_import(name[level:], package, level)
File ~\anaconda3\lib\site-packages\langchain_community\chat_message_histories\sql.py:6 3 from abc import ABC, abstractmethod 4 from typing import Any, List, Optional ----> 6 from sqlalchemy import Column, Integer, Text, create_engine 8 try: 9 from sqlalchemy.orm import declarative_base
File ~\anaconda3\lib\site-packages\sqlalchemy__init.py:12 8 from future__ import annotations 10 from typing import Any ---> 12 from . import util as _util 13 from .engine import AdaptedConnection as AdaptedConnection 14 from .engine import BaseRow as BaseRow
File ~\anaconda3\lib\site-packages\sqlalchemy\util__init__.py:15 12 from typing import TYPE_CHECKING 14 from . import preloaded as preloaded ---> 15 from ._collections import coerce_generator_arg as coerce_generator_arg 16 from ._collections import coerce_to_immutabledict as coerce_to_immutabledict 17 from ._collections import column_dict as column_dict
File ~\anaconda3\lib\site-packages\sqlalchemy\util_collections.py:38 35 import weakref 37 from ._has_cy import HAS_CYEXTENSION ---> 38 from .typing import is_non_string_iterable 39 from .typing import Literal 40 from .typing import Protocol
File ~\anaconda3\lib\site-packages\sqlalchemy\util\typing.py:56 54 from typing_extensions import TypeGuard as TypeGuard # 3.10 55 from typing_extensions import Self as Self # 3.11 ---> 56 from typing_extensions import TypeAliasType as TypeAliasType # 3.12 58 _T = TypeVar("_T", bound=Any) 59 _KT = TypeVar("_KT")
ImportError: cannot import name 'TypeAliasType' from 'typing_extensions' (C:\Users\titik\anaconda3\lib\site-packages\typing_extensions.py)
how to solve this??
how to solve this??
refer to above comments
i am facing the same issue; and i have seen above comments. the issue is bit different kindly help me with it,thanks.
iImportError: cannot import name 'TypeAliasType' from 'typing_extensions' (/opt/conda/lib/python3.10/site-packages/typing_extensions.py)
downgrading typing extension and pydantic shows the following errors:
albumentations 1.4.10 requires pydantic>=2.7.0, but you have pydantic 1.10.11 which is incompatible. albumentations 1.4.10 requires pip install typing_extensions==4.9.0, but you have typing_extensions==4.5.0 which is incompatible.
if i go with the typing_extensions==4.5.0 and pydantic>=2.7.0, it shows the first error typeAlias error
pydantic==1.10.11 typing_extensions==4.7.0
I tried to install this previous versions and it didn't like it. So I installed:!pip install pydantic>=2.5.0
and!pip install typing_extensions>=4.6.0
Then I restarted the Kernel from my env and it did work!
thanks alot
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: Sthefanie Passo @.> Sent: Tuesday, October 15, 2024 5:16:26 AM To: openai/openai-python @.> Cc: Sherazi Syed Nisar Yousaf @.>; Comment @.> Subject: Re: [openai/openai-python] Error "cannot import name 'TypeAliasType' from 'typing_extensions'" when importing openai just after installation (Issue #816)
pydantic==1.10.11 typing_extensions==4.7.0 I tried to install this previous versions and it didn't like it. So I installed: !pip install pydantic>=2.5.0 and !pip install typing_extensions>=4.6.0 Then I restarted the Kernel from my env and it did work!
— Reply to this email directly, view it on GitHubhttps://github.com/openai/openai-python/issues/816#issuecomment-2412357272, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQJUGDYZJPNIUGVRCB4NAJLZ3QYCVAVCNFSM6AAAAAA7KH4ZWKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJSGM2TOMRXGI. You are receiving this because you commented.Message ID: @.***>
Confirm this is an issue with the Python library and not an underlying OpenAI API
Describe the bug
To Reproduce
import openai
then error happens the typing_extensions version is 4.8.0(latest)
Code snippets
No response
OS
windows
Python version
Python 3.8.16
Library version
openai v 1.2.4