I just get this error while importing OpenAI “from open impot OpenAI”:
ImportError: cannot import name ‘Iterator’ from ‘typing_extensions’ (/usr/local/lib/python3.10/dist-packages/typing_extensions.py)
In the title of this message I wrote impot instead of import.
But in my code I did write “from openai import OpenAI”. And As I said, even with “import openai”, I get the same error.
It’s clear?
yeah some versions are bugged, you need to update the library (pip install openai --upgrade) (also don’t forget to restart your kernel/runtime/etc depending on what you’re on)
or alternatively, stop using the libraries. it feels to me like they bug out every couple of months and then you have to mess around with the versions again. I might be overreacting, but we stopped using them.
%pip uninstall typing_extensions
%pip install typing_extensions
%pip install openai
from dotenv import load_dotenv
from tenacity import retry, stop_after_attempt, wait_random_exponential
from typing import List
import openai
import os
Leads to
Requirement already satisfied: tenacity in /usr/local/lib/python3.10/dist-packages (8.2.3)
Requirement already satisfied: python-dotenv in /usr/local/lib/python3.10/dist-packages (1.0.0)
Found existing installation: typing_extensions 4.9.0
Uninstalling typing_extensions-4.9.0:
Would remove:
/usr/local/lib/python3.10/dist-packages/typing_extensions-4.9.0.dist-info/*
/usr/local/lib/python3.10/dist-packages/typing_extensions.py
Proceed (Y/n)? Y
Successfully uninstalled typing_extensions-4.9.0
Collecting typing_extensions
Using cached typing_extensions-4.9.0-py3-none-any.whl (32 kB)
Installing collected packages: typing_extensions
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.
tensorflow-probability 0.22.0 requires typing-extensions<4.6.0, but you have typing-extensions 4.9.0 which is incompatible.
Successfully installed typing_extensions-4.9.0
Requirement already satisfied: openai in /usr/local/lib/python3.10/dist-packages (1.7.2)
Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.10/dist-packages (from openai) (3.7.1)
Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai) (1.7.0)
Requirement already satisfied: httpx<1,>=0.23.0 in /usr/local/lib/python3.10/dist-packages (from openai) (0.26.0)
Requirement already satisfied: pydantic<3,>=1.9.0 in /usr/local/lib/python3.10/dist-packages (from openai) (1.10.13)
Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from openai) (1.3.0)
Requirement already satisfied: tqdm>4 in /usr/local/lib/python3.10/dist-packages (from openai) (4.66.1)
Requirement already satisfied: typing-extensions<5,>=4.7 in /usr/local/lib/python3.10/dist-packages (from openai) (4.9.0)
Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->openai) (3.6)
Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->openai) (1.2.0)
Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx<1,>=0.23.0->openai) (2023.11.17)
Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx<1,>=0.23.0->openai) (1.0.2)
Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.14.0)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-13-85853b39eca0> in <cell line: 10>()
8 from tenacity import retry, stop_after_attempt, wait_random_exponential
9 from typing import List
---> 10 import openai
11 import os
12
5 frames
/usr/local/lib/python3.10/dist-packages/openai/_utils/_streams.py in <module>
1 from typing import Any
----> 2 from typing_extensions import Iterator, AsyncIterator
3
4
5 def consume_sync_iterator(iterator: Iterator[Any]) -> None:
ImportError: cannot import name 'Iterator' from 'typing_extensions' (/usr/local/lib/python3.10/dist-packages/typing_extensions.py)
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
I also got the same error. Tried all things mentioned above.[quote=“obaid.oc1, post:14, topic:578166, full:true”]
i also have the same error i tried to do upgarde as well i perform all the steps which you mention above but still got the error.
[/quote]
Hi, I am using py 3.10.12 and I have the same problem. I’ve looked at various possible solutions on SO and Github, but haven’t found one that works for me. Any insight is appreciated.
In my case on Google Colab: !pip install -q openai llmx typing_extensions
→ ImportError: cannot import name ‘Iterator’ from ‘typing_extensions’ (/usr/local/lib/python3.10/dist-packages/typing_extensions.py)