英文:
Issue with connecting Postgresql with flask
问题
I will only translate the non-code portion of your text:
当我尝试将我的Flask应用连接到PostgreSQL时,我遇到了以下错误,提示我没有libpq.5。错误日志如下:
> Traceback (most recent call last):
File "/Users/noelsjacob/Desktop/Projects/pgflask/main.py", line 3, in <module>
app = create_app()
^^^^^^^^^^^^
File "/Users/noelsjacob/Desktop/Projects/pgflask/Mautourco/init.py", line 10, in create_app
db.init_app(app)
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/flask_sqlalchemy/extension.py", line 326, in init_app
engines[key] = self._make_engine(key, options, app)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/flask_sqlalchemy/extension.py", line 614, in _make_engine
return sa.engine_from_config(options, prefix="")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 804, in engine_from_config
return create_engine(url, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 2, in create_engine
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 283, in warned
return fn(*args, **kwargs) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 601, in create_engine
dbapi = dbapi_meth(**dbapi_args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 669, in import_dbapi
import psycopg2
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/psycopg2/init.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: dlopen(/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/psycopg2/_psycopg.cpython-311-darwin.so, 0x0002): Library not loaded: '@rpath/libpq.5.dylib'
Referenced from: '/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/psycopg2/_psycopg.cpython-311-darwin.so'
Reason: tried: '/opt/homebrew/lib/libpq.5.dylib' (no such file), '/opt/homebrew/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (no such file), '/usr/lib/libpq.5.dylib' (no such file
英文:
While I was trying to connect my flask app with postgresql I was getting the following error which says I don't have the libpq.5 the error log as follows
> Traceback (most recent call last):
File "/Users/noelsjacob/Desktop/Projects/pgflask/main.py", line 3, in <module>
app = create_app()
^^^^^^^^^^^^
File "/Users/noelsjacob/Desktop/Projects/pgflask/Mautourco/init.py", line 10, in create_app
db.init_app(app)
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/flask_sqlalchemy/extension.py", line 326, in init_app
engines[key] = self._make_engine(key, options, app)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/flask_sqlalchemy/extension.py", line 614, in _make_engine
return sa.engine_from_config(options, prefix="")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 804, in engine_from_config
return create_engine(url, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 2, in create_engine
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 283, in warned
return fn(*args, **kwargs) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 601, in create_engine
dbapi = dbapi_meth(**dbapi_args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 669, in import_dbapi
import psycopg2
File "/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/psycopg2/init.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: dlopen(/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/psycopg2/_psycopg.cpython-311-darwin.so, 0x0002): Library not loaded: '@rpath/libpq.5.dylib'
Referenced from: '/Users/noelsjacob/.local/share/virtualenvs/pgflask-3P3nCHJ0/lib/python3.11/site-packages/psycopg2/_psycopg.cpython-311-darwin.so'
Reason: tried: '/opt/homebrew/lib/libpq.5.dylib' (no such file), '/opt/homebrew/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (no such file), '/usr/lib/libpq.5.dylib' (no such file
答案1
得分: 1
libpq.5.dylib
库是PostgreSQL数据库的一部分,在使用psycopg2
连接数据库之前,需要在您的系统上安装它。
首先确保您的系统上安装了PostgreSQL。
如果您使用的是Mac,您可以使用Homebrew安装它:
brew install postgresql
如果PostgreSQL已经安装在您的机器上,可能是因为libpq.5.dylib
库不在您的系统库路径中。因此,请确保设置DYLD_LIBRARY_PATH
变量:
export DYLD_LIBRARY_PATH="/usr/local/Cellar/postgresql/<version>/lib/postgresql/:$DYLD_LIBRARY_PATH"
英文:
The libpq.5.dylib
library is a part of the PostgreSQL database, it needs to be installed on your system before you can use psycopg2
to connect to the database.
First, make sure that PostgreSQL is installed on your system.
If you're using Mac, you can install it using Homebrew:
brew install postgresql
In case PostgreSQL is already installed on your machine, it might be that libpq.5.dylib
library is not in your system's library path. So make sure DYLD_LIBRARY_PATH
variable is set:
export DYLD_LIBRARY_PATH="/usr/local/Cellar/postgresql/<version>/lib/postgresql/:$DYLD_LIBRARY_PATH"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论