Skip to content
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

SNOW-634755: ImportError: cannot import name 'NamedTuple' from 'typing_extensions' #1206

Closed
mrcarlosrendon opened this issue Jul 25, 2022 · 27 comments · Fixed by #1208
Closed

Comments

@mrcarlosrendon
Copy link

mrcarlosrendon commented Jul 25, 2022

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?

Issue happened on vm, but reproduces on my mac

Python 3.9.7 (default, Oct 13 2021, 06:45:31) [Clang 13.0.0 (clang-1300.0.29.3)]

  1. What operating system and processor architecture are you using?

macOS-12.4-x86_64-i386-64bit

  1. What are the component versions in the environment (pip freeze)?

from mac laptop - hard to pull from vm where issue happened
aniso8601==9.0.1 appnope==0.1.2 Authlib==0.15.4 backcall==0.2.0 boto3==1.16.10 botocore==1.19.10 certifi==2021.10.8 cffi==1.14.6 charset-normalizer==2.0.7 cryptography==35.0.0 cypari==2.4.1 decorator==4.4.2 future==0.18.2 FXrays==1.3.5 graphene==3.0 graphql-core==3.1.7 graphql-relay==3.1.5 idna==3.2 ipython==7.21.0 ipython-genutils==0.2.0 jedi==0.18.0 jmespath==0.10.0 networkx==2.5 oauthlib==3.1.1 parso==0.8.1 pexpect==4.8.0 pickleshare==0.7.5 plink==2.3.1 prompt-toolkit==3.0.17 ptyprocess==0.7.0 pycparser==2.20 Pygments==2.8.1 PyJWT==2.2.0 pypng==0.0.20 python-dateutil==2.8.1 python-snappy==0.6.0 requests==2.26.0 s3transfer==0.3.3 six==1.15.0 snappy-manifolds==1.1.2 spherogram==1.8.3 traitlets==5.0.5 typing_extensions==4.2.0 urllib3==1.25.11 wcwidth==0.2.5

  1. What did you do?
conn = snowflake.connector.connect(
        user=snowflake_user,
        role=snowflake_role,
        password=snowflake_pass,
        account=snowflake_acc,
        database=database,
        schema=schema
    )

fails with ImportError: cannot import name 'NamedTuple' from 'typing_extensions' (/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/typing_extensions.py)

Some root cause analysis from my side --

Latest version of Snowflake-connector ('2.7.10') includes cache.py, which imports NamedTuple

from typing_extensions import NamedTuple, Self
https://github.com/snowflakedb/snowflake-connector-python/blob/main/src/snowflake/connector/cache.py#L12

This fails if using typing_extensions < 4.3.0, as NamedTuple was added in this commit python/typing_extensions@7c28357

I believe you need to change the requirements to be >= 4.3.0 for typing_extentions https://github.com/snowflakedb/snowflake-connector-python/blob/main/setup.cfg#L59

  1. What did you expect to see?

No error message when connecting to snowflake.

What should have happened and what happened instead?

Able to connect to snowflake.

  1. Can you set logging to DEBUG and collect the logs?

No - above root cause analysis in part 4 explains issue and how to fix it on Snowflake side.

--- full failure traceback from vm starting with Snowflake code

File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/__init__.py", line 51, in Connect
--
return SnowflakeConnection(**kwargs)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/connection.py", line 292, in __init__
self.connect(**kwargs)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/connection.py", line 542, in connect
self.__open_connection()
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/connection.py", line 781, in __open_connection
self._authenticate(auth_instance)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/connection.py", line 1044, in _authenticate
self.__authenticate(self.__preprocess_auth_instance(auth_instance))
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/connection.py", line 1064, in __authenticate
auth.authenticate(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/auth.py", line 257, in authenticate
ret = self._rest._post_request(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 704, in _post_request
ret = self.fetch(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 794, in fetch
ret = self._request_exec_wrapper(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 917, in _request_exec_wrapper
raise e
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 837, in _request_exec_wrapper
return_object = self._request_exec(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 1116, in _request_exec
raise err
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 1018, in _request_exec
raw_ret = session.request(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/urllib3/connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/urllib3/connectionpool.py", line 1042, in _validate_conn
conn.connect()
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/urllib3/connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/ssl_wrap_socket.py", line 78, in ssl_wrap_socket_with_ocsp
from .ocsp_asn1crypto import SnowflakeOCSPAsn1Crypto as SFOCSP
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/ocsp_asn1crypto.py", line 47, in <module>
from snowflake.connector.ocsp_snowflake import SnowflakeOCSP
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/ocsp_snowflake.py", line 71, in <module>
from .cache import SFDictCache
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/cache.py", line 12, in <module>
from typing_extensions import NamedTuple, Self
ImportError: cannot import name 'NamedTuple' from 'typing_extensions' (/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/typing_extensions.py)
@github-actions github-actions bot changed the title ImportError: cannot import name 'NamedTuple' from 'typing_extensions' SNOW-634755: ImportError: cannot import name 'NamedTuple' from 'typing_extensions' Jul 25, 2022
@Nakulbajaj101
Copy link

We had to go back to 2.7.9

@mrcarlosrendon
Copy link
Author

pip install 'typing-extensions>=4.3.0' with version 2.7.10 should also do the trick.

@wilson-vaquen
Copy link

As per @mrcarlosrendon, typing extensions from version 4 uses semantic versioning, so probably the most elegant solution is pip install 'typing-extensions>=4.3.0'
image
https://pypi.org/project/typing-extensions/

@roshan-abady
Copy link

FYI, We have encountered the same error today as well.

@viktorossmark
Copy link

viktorossmark commented Jul 26, 2022

We are also getting the same error all over the place. You probably need to update the requirements. Adding typing-extensions>=4.3.0 in our requirements.txt file and updated our MWAA environment fixed the issue.

@Meiky246
Copy link

Same problem here, and !pip install 'typing-extensions>=4.3.0' did not solve it (using google colab) :(

@david-p-wqpredtech
Copy link

Same problem here all of a sudden. %pip install 'typing-extensions>=4.3.0' solved it on Databricks notebooks.

@FransGer
Copy link

We are also getting the same error all over the place. You probably need to update the requirements. Adding typing-extensions>=4.3.0 in our requirements.txt file and updated our MWAA environment fixed the issue.

@viktorossmark - this just saved me a hell of a lot of time. Thank you very much!!!

@DianGermishuizen
Copy link

We are also getting the same error all over the place. You probably need to update the requirements. Adding typing-extensions>=4.3.0 in our requirements.txt file and updated our MWAA environment fixed the issue.

Hi viktorossmark
Your solution worked perfectly for our AWS MWAA instance as well, thank you very much for saving our behinds!

@agshiv92
Copy link

Same problem here, and !pip install 'typing-extensions>=4.3.0' did not solve it (using google colab) :(

Same here the solution did not work for colab

@wiktor2200
Copy link

@agshiv92 take a look on my solution for snowflake-sqlalchemy in Superset's repository. In different repositories this can be caused by different things. There there was a problem with python dependencies defined with <3.0.0 so it downloaded newest version of snowflake-connection-python because it fulfilled condition while still wasn't incompatible (needed 2.7.9 there).
Maybe the same case exists in Google Colab code. 🤔

@christianrua
Copy link

Same problem here all of a sudden. %pip install 'typing-extensions>=4.3.0' solved it on EC2 Airflow cluster

@sfc-gh-mkeller
Copy link
Collaborator

sfc-gh-mkeller commented Jul 26, 2022

pip install 'typing-extensions>=4.3.0' with version 2.7.10 should also do the trick.

This is the right solution, I forgot to add a lower pin to the new dependency. We'll go ahead and release a new version with this fixed and yank 2.7.10!

@hc1wwilger
Copy link

Happening in AWS Glue 2.0 as well, fix was adding typing-extensions to the extra python modules, a la:

DefaultArguments:
        "--additional-python-modules": "mysql.connector, snowflake-connector-python, awswrangler, typing-extensions>=4.3.0"

@rahulsatasia
Copy link

pip install 'typing-extensions>=4.3.0' worked for me in python 3.9+

@sfc-gh-mkeller
Copy link
Collaborator

sfc-gh-mkeller commented Jul 26, 2022

Re-opening for a few extra days. Just so that it's easier for others to find this issue

@chingc
Copy link

chingc commented Jul 26, 2022

The suggested solution of installing typing-extensions 4.3.0 doesn't work for Python 3.6, which unfortunately, my company is still using. Support for 3.6 was dropped in 4.2.0.

Edit: Just noticed 2.7.10 was yanked from PyPI and our requirements.txt also wasn't pinning snowflake-connector-python to 2.7.9. I pinned 2.7.9. Problem solved. :)

@Meiky246
Copy link

Weird, yesterday it worked, but today I get the same error again - any idea why this is happeneing?

@maphany
Copy link

maphany commented Aug 2, 2022

Also experiencing the same error on google colab.

timmc-edx added a commit to openedx/edx-platform that referenced this issue Aug 2, 2022
timmc-edx added a commit to openedx/edx-platform that referenced this issue Aug 2, 2022
@HelmutSchuster
Copy link

One must follow exactly the instructions in https://docs.snowflake.com/en/developer-guide/snowpark/python/setup.html and not mix conda and pip.

@jamesowers-roo
Copy link

In case anyone else arrives and in need, I restricted my version of snowflake-connector-python to temporarily fix. I added

snowflake-connector-python = ">=2.6.2,<2.7" 

to my pyproject.toml

@alexblund
Copy link

How do I update it running locally with docker? Having the same probnlem.

@viktorossmark
Copy link

How do I update it running locally with docker? Having the same probnlem.

@alexblund Update the requirements.txt file and rebuild the docker image!

@sfc-gh-mkeller
Copy link
Collaborator

2.7.11 release version added the missing lower version pin and the problematic version 2.7.10 was yanked from PyPi.
Make sure that you are not pinning to 2.7.10, this seems to force pip to still install the yanked version anyway.
Again I apologize for the issue, please don't hesitate to reach out if you have issues!

@salmanea
Copy link

salmanea commented Mar 13, 2023

March 2023 and I get the exact same error and doing pip install 'typing-extensions>=4.3.0' does NOT help.

@GRSARVESH
Copy link

March 2023 and I get the exact same error and doing pip install 'typing-extensions>=4.3.0' does NOT help.

Any update on this?

@g-muller
Copy link

Having the same issue as @salmanea and @GRSARVESH, in this case on Azure Databricks. @sfc-gh-mkeller is there an update?

In the meantime, pinning to version 3.0.0 instead of current 3.0.4 'fixed' the error, didn't try pinning other versions because the comments above made me suspect this issue was (re)introduced in the March release of 3.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.