python - 导入错误 : cannot import name 'PY2'

标签 python python-3.x sqlalchemy

想用SQLalchemy连接snowflake。为雪花创建引擎时出现以下错误:

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="***"))

最佳答案

我在 tested requirements page 匹配了所有依赖项.问题已通过 pip install --upgrade snowflake-sqlalchemy 为我解决.我在运行 Python 3.7.6与版本 2.2.1snowflake-connector-python

关于python - 导入错误 : cannot import name 'PY2' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59982458/

相关文章:

python - 学习 UNIX/Linux 哪个平台更好(Kali Linux 与 Red Hat 或其他)

mysql - IOError 没有这样的文件或目录,但文件确实存在

python - SQLalchemy 查询中的正则表达式?

javascript - 我很好奇python是如何连接到网站的

python - 如何在 3 个表上的 SQLAlchemy 中执行 JOIN,其中一个在其他两个表之间进行映射?

python - sqlalchemy 测试 : adding same user twice not throwing exception when unique=True

python - 如何捕获通过 exec() 执行的 ZeroDivisionError 的参数?

python - 在 python 日期时间中处理月份

python - TypeError : must be string or buffer, not int:执行 sqlAlchemy 查询时

Python将元素插入列表中无限循环的奇怪行为