我正在构建一个Flask应用程序来创建一个点对点的市场。在我的新计算机上运行代码时遇到了问题。代码可以在这里找到:https://github.com/ripemelon/flaskbyge。
flaskbyge$ python run.py
/home/byge/.local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py:834: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
Traceback (most recent call last):
File "run.py", line 1, in <module>
from flaskbyge import app
File "/home/byge/Desktop/flaskbyge/flaskbyge/__init__.py", line 15, in <module>
from flaskbyge import routes
File "/home/byge/Desktop/flaskbyge/flaskbyge/routes.py", line 33
flash(f'Account created for {form.username.data}! You can now log in','success' )***当我尝试使用SQLAlchemy数据库运行Flask模块时,它给出了这个错误。
发布于 2020-08-26 17:25:27
正如您在错误消息的第一行中所看到的,您正在使用Python2.7。这个应用程序似乎至少是为Python3.6开发的,因为正如您在最后一行(flash(f'Account ...))中看到的那样,使用的是格式化字符串。
这对我来说很有效:
$ cd $ROOT_FOLDER_OF_YOUR_APP
$ python3.8 -m venv flaskbyge
$ source flaskbyge/bin/activate
$ pip install -r requirements.txt
$ python run.py对我来说,python3.8显然是在运行Python3.8解释器。您可以使用不同的命令,可能是python3或类似命令。也许Python3.6就足够了。注意,在激活虚拟环境之后,python和pip命令引用正确的Python版本(这里是Python3.8)。
毕竟,似乎你只需要确保你不会通过Python2.7启动应用程序。
https://stackoverflow.com/questions/63593810
复制相似问题