当前位置: 首页 > 工具软件 > psycopg > 使用案例 >

MacOS: couldn‘t import psycopg ‘c‘ implementation: No module named ‘psycopg_c‘

费朗
2023-12-01

在苹果系统上,进行Tortoise-orm的单元测试时,报了如下错误:

___________________________________________________ ERROR collecting tests/test_default.py ____________________________________________________
ImportError while importing test module '/Users/mac10.12/trying/tortoise-orm/tests/test_default.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_default.py:11: in <module>
    from tortoise.backends.psycopg import PsycopgClient
tortoise/backends/psycopg/__init__.py:1: in <module>
    from .client import PsycopgClient
tortoise/backends/psycopg/client.py:5: in <module>
    import psycopg
../../Library/Caches/pypoetry/virtualenvs/tortoise-orm-t8QiqUiC-py3.10/lib/python3.10/site-packages/psycopg/__init__.py:9: in <module>
    from . import pq  # noqa: F401 import early to stabilize side effects
../../Library/Caches/pypoetry/virtualenvs/tortoise-orm-t8QiqUiC-py3.10/lib/python3.10/site-packages/psycopg/pq/__init__.py:114: in <module>
    import_from_libpq()
../../Library/Caches/pypoetry/virtualenvs/tortoise-orm-t8QiqUiC-py3.10/lib/python3.10/site-packages/psycopg/pq/__init__.py:106: in import_from_libpq
    raise ImportError(
E   ImportError: no pq wrapper available.
E   Attempts made:
E   - couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
E   - couldn't import psycopg 'binary' implementation: cannot import name Trace
E   - couldn't import psycopg 'python' implementation: libpq library not found

使用`pip list|grep psy`看了一下,发现psycopg_c确实没装上

必应一下,很快就找到了解决方案:https://github.com/psycopg/psycopg/issues/364

把psycopg升级到3.1.5以上版本就好了:

pip install -U "psycopg>=3.1.5"

 类似资料: