gpt4 book ai didi

python - 什么是导入错误 : Symbol not found: _PQencryptPasswordConn mean and how do I fix it?

转载 作者:行者123 更新时间:2023-11-29 13:39:37 25 4
gpt4 key购买 nike

我正在尝试在我的 Flask_App 所在的下载目录中执行“flask run”。我的 Flask_App 是“applications.py”。当我在开发环境中执行“flask run”时,我得到了一个 URL。将 URL 粘贴到 Safari 后,出现此错误。


ImportError: dlopen(/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Symbol not found: _PQencryptPasswordConn
Referenced from: /Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
Expected in: /usr/lib/libpq.5.6.dylib
in /Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so

我使用的是 MacOSX High Sierra。我的 PostgreSQL 是版本 11。我的 python 更新到版本 3.7。并且 pip 已升级,psycopg 版本为 2.8.3。我尝试在各种目录上运行“flask run”,并尝试将“applications.py”移动到我当前所在的不同库和目录中。我试过使用 sudo 但我意识到我不知道密码。过去,当我不小心删除了管理员帐户的管理员身份时,我强制创建了另一个管理员帐户……不知道这是否影响了 sudo,但它不接受我当前的管理员密码。我在安装 psycopg2 时也遇到了问题,但通过重新下载 PostgreSQL 11 解决了这个问题。我也使用 pip 成功安装了 SQLAlchemy 和 Flask-Session。

我尝试注释掉代码中的几行,并将其缩小到“create_engine”函数,因为只是让“os.getenv("DATABASE_URL")”按预期运行我的页面。

这是我的“applications.py”代码

import os

from flask import Flask, session
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

app = Flask(__name__)

# Check for environment variable
if not os.getenv("DATABASE_URL"):
raise RuntimeError("DATABASE_URL is not set")

# Configure session to use filesystem
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)

# Set up database
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))


@app.route("/")
def index():
return "Project 1: TODO"

粘贴 URL 后,我希望页面显示文本“项目 1:TODO”但是,我收到此错误消息:

flask.cli.NoAppException: While importing "applications", an ImportError was raised:

Traceback (most recent call last):
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 235, in locate_app
__import__(module_name)
File "/Users/dhruvaiyer/Downloads/applications.py", line 20, in <module>
engine = create_engine(os.getenv("DATABASE_URL"))
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/__init__.py", line 425, in create_engine
return strategy.create(*args, **kwargs)
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 81, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 584, in dbapi
import psycopg2
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: dlopen(/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Symbol not found: _PQencryptPasswordConn
Referenced from: /Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
Expected in: /usr/lib/libpq.5.6.dylib
in /Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 325, in __call__
self._flush_bg_loading_exception()
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 313, in _flush_bg_loading_exception
reraise(*exc_info)
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 302, in _load_app
self._load_unlocked()
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 317, in _load_unlocked
self._app = rv = self.loader()
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 372, in load_app
app = locate_app(self, import_name, name)
File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 242, in locate_app
'\n\n{tb}'.format(name=module_name, tb=traceback.format_exc())
flask.cli.NoAppException: While importing "applications", an ImportError was raised: Traceback (most recent call last): File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 235, in locate_app __import__(module_name) File "/Users/dhruvaiyer/Downloads/applications.py", line 20, in <module> engine = create_engine(os.getenv("DATABASE_URL")) File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/__init__.py", line 425, in create_engine return strategy.create(*args, **kwargs) File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 81, in create dbapi = dialect_cls.dbapi(**dbapi_args) File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 584, in dbapi import psycopg2 File "/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/psycopg2/__init__.py", line 50, in <module> from psycopg2._psycopg import ( # noqa ImportError: dlopen(/Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Symbol not found: _PQencryptPasswordConn Referenced from: /Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so Expected in: /usr/lib/libpq.5.6.dylib in /Users/dhruvaiyer/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
#The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.

同样的代码也出现在我的终端窗口中。关于如何进行或如何解决此问题的任何建议?非常感谢您!

最佳答案

我在克隆并安装 Django 项目后遇到了同样的错误。我通过卸载 psycopg2 然后重新安装它来解决它,所有这些都在虚拟环境中:

pip uninstall psycopg2 然后 pip install psycopg2

关于python - 什么是导入错误 : Symbol not found: _PQencryptPasswordConn mean and how do I fix it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57236722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com