flask框架学习-01

裁判文书网

PS D:\python-tutorial-master> flask run
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the c
urrent directory.

venv 虚拟环境

"python -m venv env" 是创建一个 Python 项目的虚拟环境的命令

"venv" 模块是 Python 3 的一个内置模块,提供了创建轻量级 "虚拟环境" 的支持,每个虚拟环境都有其自己独立的 Python 包和依赖。虚拟环境存储在当前目录下名为 "env" 的子目录中。

python -m venv env   --3
virtualenv env   --2

要创建虚拟环境,您需要在终端或命令提示符中输入此命令,并确保在所需的目录中:

python -m venv env  # use `virtualenv env` for Python2, use `python3 ...` for Python3 on Linux & macOS

激活先前创建的 Python 虚拟环境的命令:env\Scripts\activate
退出虚拟环境:deactivate

pip install -r requirements.txt


Requirement already satisfied: Flask==1.1.2 in d:\amaconda\lib\site-packages (from -r requirements.txt (line 1)) (1.1.2)
Collecting Werkzeug==2.2.3
  Using cached Werkzeug-2.2.3-py3-none-any.whl (233 kB)
Collecting Flask_Login==0.5.0
  Downloading Flask_Login-0.5.0-py2.py3-none-any.whl (16 kB)
Collecting click==7.1.2
  Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
     ---------------------------------------- 82.8/82.8 kB 272.7 kB/s eta 0:00:00
Collecting Flask_SQLAlchemy==2.4.0
  Downloading Flask_SQLAlchemy-2.4.0-py2.py3-none-any.whl (17 kB)
Collecting python-dotenv==0.19.0
  Downloading python_dotenv-0.19.0-py2.py3-none-any.whl (17 kB)
Requirement already satisfied: Jinja2 in d:\amaconda\lib\site-packages (from -r requirements.txt (line 7)) (2.11.3)
Requirement already satisfied: MarkupSafe==1.1.1 in d:\amaconda\lib\site-packages (from -r requirements.txt (line 8)) (1.1.1)
Collecting SQLAlchemy==1.3.6
  Downloading SQLAlchemy-1.3.6.tar.gz (5.9 MB)
     ---------------------------------------- 5.9/5.9 MB 3.3 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Requirement already satisfied: itsdangerous>=0.24 in d:\amaconda\lib\site-packages (from Flask==1.1.2->-r requirements.txt (line 1)) (2.0.1)
INFO: pip is looking at multiple versions of flask to determine which version is compatible with other requirements. This could take a while.
Collecting Flask==1.1.2
  Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
     ---------------------------------------- 94.6/94.6 kB 5.3 MB/s eta 0:00:00

报错

ERROR: Cannot install -r requirements.txt (line 2) and MarkupSafe==1.1.1 because these package versions have conflicting dependencies.
The conflict is caused by:
    The user requested MarkupSafe==1.1.1
    werkzeug 2.2.3 depends on MarkupSafe>=2.1.1
To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

forge" 命令通常用于生成一些测试数据或者初始化数据库

"dotenv" 是一个 Python 库,它用于从文件中加载环境变量。它通常用于在 Flask 应用程序中存储敏感的配置信息(例如 API 密钥或数据库密码)。

因此,您需要确保已经在虚拟环境中安装了 "dotenv" 模块。可以通过以下命令来安装它:

* Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.
Error: While importing "wsgi", an ImportError was raised:
Traceback (most recent call last):
  File "D:\Amaconda\lib\site-packages\flask\cli.py", line 240, in locate_app
    __import__(module_name)
  File "D:\python-tutorial-master\python-tutorial-master\04_flask\wsgi.py", line 4, in <module>
    from dotenv import load_dotenv
ModuleNotFoundError: No module named 'dotenv'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哈都婆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值