我正在使用Flask制作一个私人信使。这个Github code很有意思。在Ubuntu 22.04的命令行上执行flask run
,按照Github页面上的“README.md“上的说明,计算机返回以下错误:
ImportError: cannot import name 'escape' from 'jinja2' (/home/home/.local/lib/python3.10/site-packages/jinja2/__init__.py)
字符串
使用“pip 3 install -r requirements.txt”安装的“requirements.txt”文件如下所示:
Flask_SQLAlchemy==2.4.1
Flask_JWT_Extended==3.24.1
Flask_SocketIO==4.2.1
Flask_RESTful==0.3.8
Flask_Migrate==2.5.3
Flask==1.1.1
Flask_Cors==3.0.8
Werkzeug==0.15.4
SQLAlchemy==1.3.5
型
请帮忙。
我按照给here的说明去做了,没有用。
以上部分已于2023年11月3日通过AKX使用以下答案解决。
按照README.md
上的说明操作,flask run
和npm run serve
现在都运行良好。在README.md
上,数据库部分令人困惑。我的尝试和错误如下:
$ python3
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from database import init_db
>>> init_db()
Traceback (most recent call last):
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2262, in _wrap_pool_connect
return fn()
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 363, in connect
return _ConnectionFairy._checkout(self)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 760, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
rec = pool._do_get()
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 138, in _do_get
with util.safe_reraise():
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 154, in reraise
raise value
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 136, in _do_get
return self._create_connection()
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
return _ConnectionRecord(self)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
self.__connect(first_connect_check=True)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 639, in __connect
connection = pool._invoke_creator(self)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
return dialect.connect(*cargs, **cparams)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 451, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/home/home/.local/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "postgres"
connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "postgres"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/home/Documents/doctor_jha/flask/FlaskChat/api/database.py", line 15, in init_db
Base.metadata.create_all(bind=engine)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 4286, in create_all
bind._run_visitor(
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2032, in _run_visitor
with self._optional_conn_ctx_manager(connection) as conn:
File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2024, in _optional_conn_ctx_manager
with self._contextual_connect() as conn:
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2226, in _contextual_connect
self._wrap_pool_connect(self.pool.connect, None),
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2265, in _wrap_pool_connect
Connection._handle_dbapi_exception_noconnection(
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1536, in _handle_dbapi_exception_noconnection
util.raise_from_cause(sqlalchemy_exception, exc_info)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 399, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 153, in reraise
raise value.with_traceback(tb)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2262, in _wrap_pool_connect
return fn()
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 363, in connect
return _ConnectionFairy._checkout(self)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 760, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
rec = pool._do_get()
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 138, in _do_get
with util.safe_reraise():
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 154, in reraise
raise value
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 136, in _do_get
return self._create_connection()
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
return _ConnectionRecord(self)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
self.__connect(first_connect_check=True)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 639, in __connect
connection = pool._invoke_creator(self)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
return dialect.connect(*cargs, **cparams)
File "/home/home/.local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 451, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/home/home/.local/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "postgres"
connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "postgres"
(Background on this error at: http://sqlalche.me/e/e3q8)
>>>
1条答案
按热度按时间eni9jsuy1#
该存储库没有正确地锁定传递依赖项,所以您最终安装了一个[不能导出
escape
的Jinja 2的最新版本](https://jinja.jintsprojects.com/en/3.1.x/changes/#version-3-1-0,https://github.com/pallets/jinja/pull/1544)。安装旧版本的Jinja,以及兼容版本的依赖MarkupSafe:
字符串