Unable to update typing-extensions

Question:
I would like to implement the code from this repository on Replit but the code fails to run which seems to have to do with an outdated version of the typing-extensions module. I already upgraded it to a newer version (4.8.0) and it tells me that upgrade has worked successfully but when I do a pip check it indicates that my Repl is still stuck at version 4.5.0.

This is the error message I am getting:

ImportError: cannot import name 'TypeAliasType' from 'typing_extensions' (/nix/store/nv13brd9hw3wbajaxkrgfsngyfjg0xjj-python3.10-typing-extensions-4.5.0/lib/python3.10/site-packages/typing_extensions.py)
Traceback:
File "/home/runner/conversational-chatbot-groq-1/.pythonlibs/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 535, in _run_script
    exec(code, module.__dict__)
File "/home/runner/conversational-chatbot-groq-1/app.py", line 3, in <module>
    from groq import Groq
File "/home/runner/conversational-chatbot-groq-1/.pythonlibs/lib/python3.10/site-packages/groq/__init__.py", line 3, in <module>
    from . import types
File "/home/runner/conversational-chatbot-groq-1/.pythonlibs/lib/python3.10/site-packages/groq/types/__init__.py", line 5, in <module>
    from .model import Model as Model
File "/home/runner/conversational-chatbot-groq-1/.pythonlibs/lib/python3.10/site-packages/groq/types/model.py", line 5, in <module>
    from .._models import BaseModel
File "/home/runner/conversational-chatbot-groq-1/.pythonlibs/lib/python3.10/site-packages/groq/_models.py", line 20, in <module>
    from pydantic.fields import FieldInfo
File "/home/runner/conversational-chatbot-groq-1/.pythonlibs/lib/python3.10/site-packages/pydantic/fields.py", line 18, in <module>
    from . import types
File "/home/runner/conversational-chatbot-groq-1/.pythonlibs/lib/python3.10/site-packages/pydantic/types.py", line 33, in <module>
    from typing_extensions import Annotated, Literal, Protocol, TypeAlias, TypeAliasType, deprecated

And here is an extract of my shell commands and responses:

~/conversational-chatbot-groq-1$ pip install --upgrade typing-extensions==4.8.0

Collecting typing-extensions==4.8.0
  Downloading typing_extensions-4.8.0-py3-none-any.whl.metadata (3.0 kB)
Downloading typing_extensions-4.8.0-py3-none-any.whl (31 kB)
Installing collected packages: typing-extensions
Successfully installed typing-extensions-4.10.0
~/conversational-chatbot-groq-1$ 
~/conversational-chatbot-groq-1$ pip check
groq 0.4.1 has requirement typing-extensions<5,>=4.7, but you have typing-extensions 4.5.0.
langchain-core 0.1.21 has requirement packaging<24.0,>=23.2, but you have packaging 23.0.
openai 1.12.0 has requirement typing-extensions<5,>=4.7, but you have typing-extensions 4.5.0.
pydantic 2.6.3 has requirement typing-extensions>=4.6.1, but you have typing-extensions 4.5.0.
pydantic-core 2.16.3 has requirement typing-extensions!=4.7.0,>=4.6.0, but you have typing-extensions 4.5.0.
torch 2.2.0 has requirement typing-extensions>=4.8.0, but you have typing-extensions 4.5.0.

Does anybody have any idea what I am doing wrong? This is the link to my Repl

Thanks in advance!

Replit Profile: https://replit.com/@urm3l

Could you try modifying the requirements.txt file to explicitly specify the newer typing-extensions version?

2 Likes

typing_extensions is one of the builtin, immutable modules that are in the provided python interpreter. But you can also install it locally. It is likely that pip, which is from the python interpreter, is just recognizing the python interpreter’s typing_extensions, not the one in .pythonlibs.
Another one of these is setuptools, which when poetry tries to update, it fails.
I haven’t yet found a way to get around these immutable modules and install one’s own and have pip recognize it.
Also, when you import typing_extensions, check if it is the local installed version or the builtin one.

1 Like

Sorry for asking but how do I check if it’s the local installed version or the built-in? And how would I install it locally?

Am I correct with my assumption that there is a chance that there is actually no way to solve this issue when it’s not possible to make pip recognize the correct version?

@Firepup650 Thanks for the input. Tried your suggestion but it didn’t work

tbh my best suggestion here is to change it to use poetry instead of pip, but I don’t know if that’d fix anything

@urm3l does this repl work for you? (Word of warning to anyone who tries, packages in this repl take up 8.9GB)

Sadly it doesn’t. Getting the same error message as before :confused:

Okay, I think there are ways to fix this.

First, you have already locally installed typing_extensions using pip or poetry. It resides in .pythonlibs/lib/python3.10/site-packages. This has the correct version and is recognized by the package managers.

Now, let’s check what version of typing_extensions is actually used. Bring up the python interpreter or a file or whatever, and:

import typing_extensions
print(typing_extensions.__file__)

You want it to be your /home/runner/.../.pythonlibs/.../site-packages path.
But it probably says /nix/store/nv13brd9hw3wbajaxkrgfsngyfjg0xjj-python3.10-typing-extensions-4.5.0/lib/python3.10/site-packages/typing_extensions.py, or something similar. You can see that this one is version 4.5.0 from the path.

So how do we make our version imported first? The PYTHONPATH environment variable determines which package takes priority.
(It seems yours has a lot more paths than usual, probably from one of your nix packages, and one of these paths is to typing_extensions 4.5.0.)

To fix, edit PYTHONPATH by inserting this at the bottom of .replit hidden file:

[env]
PYTHONPATH = "$REPL_HOME/.pythonlibs/lib/python3.10/site-packages:$PYTHONPATH"

and refresh. This should fix the issue by prioritizing your installed typing_extensions, by putting its directory as the first path in PYTHONPATH.

(Note: historically, it was recommended to use poetry over pip, pyproject.toml over requirements.txt, in replit, but it looks like there have been changes to fix this recently.)

1 Like

Thanks for your help. I still wasn’t able to fix it as I was running into issues repeatedly. I posted a bounty about it, feel free to solve it :slight_smile:

https://replit.com/bounties/@urm3l/fix-a-probably-simpl

Hey @urm3l , I have invited you to the working repo. Please check it and accept me on https://replit.com/bounties/@urm3l/fix-a-probably-simpl?t=applications