문제 설명
ImportError: 'PY2' 이름을 가져올 수 없습니다. (ImportError: cannot import name 'PY2')
SQLalchemy를 사용하여 눈송이에 연결하고 싶습니다. 눈송이용 엔진을 생성하는 동안 다음 오류가 발생합니다.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\mithi\AppData\Local\Programs\Python\Python38‑32\lib\site‑packages\sqlalchemy\engine\__init__.py", line 479, in create_engine
return strategy.create(*args, **kwargs)
File "C:\Users\mithi\AppData\Local\Programs\Python\Python38‑32\lib\site‑packages\sqlalchemy\engine\strategies.py", line 61, in create
entrypoint = u._get_entrypoint()
File "C:\Users\mithi\AppData\Local\Programs\Python\Python38‑32\lib\site‑packages\sqlalchemy\engine\url.py", line 172, in _get_entrypoint
cls = registry.load(name)
File "C:\Users\mithi\AppData\Local\Programs\Python\Python38‑32\lib\site‑packages\sqlalchemy\util\langhelpers.py", line 222, in load
return self.impls[name]()
File "C:\Users\mithi\AppData\Local\Programs\Python\Python38‑32\lib\site‑packages\pkg_resources\__init__.py", line 2443, in load
return self.resolve()
File "C:\Users\mithi\AppData\Local\Programs\Python\Python38‑32\lib\site‑packages\pkg_resources\__init__.py", line 2449, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "C:\Users\mithi\AppData\Local\Programs\Python\Python38‑32\lib\site‑packages\snowflake\sqlalchemy\__init__.py", line 12, in <module>
from .util import _url as URL
File "C:\Users\mithi\AppData\Local\Programs\Python\Python38‑32\lib\site‑packages\snowflake\sqlalchemy\util.py", line 9, in <module>
from snowflake.connector.compat import (PY2, IS_STR)
ImportError: cannot import name 'PY2' from 'snowflake.connector.compat' (C:\Users\mithi\AppData\Local\Programs\Python\Python38‑32\lib\site‑packages\snowflake\connector\compat.py)
엔진 생성 코드는 다음과 같습니다.
from sqlalchemy import create_engine
from sqlalchemy.engine.url import URL
create_engine(URL("snowflake", username="***",password="***",host="***"))
참조 솔루션
방법 1:
I matched all dependencies at tested requirements page. Issue was resolved for me with pip install ‑‑upgrade snowflake‑sqlalchemy
. I'm running Python 3.7.6
with version 2.2.1
of snowflake‑connector‑python
방법 2:
It seems to relate to the release of snowflake‑connector‑python
version 2.2.0
. Setting it to <2.2.0
fixed it for me.
(by Mithil Bhoras、Slizzard Wizzard、sgieske)