pip freeze 需求文件requirements.txt的创建及使用 虚拟环境

总结:

1、输出安装的包信息,并在另一个环境快速安装

  1. Generate output suitable for a requirements file.

    $ pip freeze
    docutils==0.11
    Jinja2==2.7.2
    MarkupSafe==0.19
    Pygments==1.6
    Sphinx==1.2.2
    
  2. Generate a requirements file and then install from it in another environment.

    $ env1/bin/pip freeze > requirements.txt
    $ env2/bin/pip install -r requirements.txt

python笔记---需求文件requirements.txt的创建及使用 - loyachen的专栏 - CSDN博客
https://blog.csdn.net/loyachen/article/details/52028825

python项目中必须包含一个 requirements.txt 文件,用于记录所有依赖包及其精确的版本号。以便新环境部署。

在虚拟环境中使用pip生成:
(venv) $ pip freeze >requirements.txt

安装或升级包后,最好更新这个文件。

需求文件的内容示例如下:

alembic==0.8.6
bleach==1.4.3
click==6.6
dominate==2.2.1
Flask==0.11.1
Flask-Bootstrap==3.3.6.0
Flask-Login==0.3.2
Flask-Migrate==1.8.1
Flask-Moment==0.5.1
Flask-PageDown==0.2.1
Flask-Script==2.0.5
Flask-SQLAlchemy==2.1
Flask-WTF==0.12
html5lib==0.9999999
itsdangerous==0.24
Jinja2==2.8
Mako==1.0.4
Markdown==2.6.6
MarkupSafe==0.23
PyMySQL==0.7.5
python-editor==1.0.1
six==1.10.0
SQLAlchemy==1.0.14
visitor==0.1.3
Werkzeug==0.11.10
WTForms==2.1

当需要创建这个虚拟环境的完全副本,可以创建一个新的虚拟环境,并在其上运行以下命令:

当需要创建这个虚拟环境的完全副本,可以创建一个新的虚拟环境,并在其上运行以下命令:

(venv) $ pip install -r requirements.txt




注释语法 前缀 #




指定git仓库的分支

pymysql==0.7.11
git+ssh://git@gitlab-test.test.com:18122/python/test.core.git@fxl
git+ssh://git@gitlab-test.test.com:18122/python/test.ucenter_sdk.git
git+ssh://git@gitlab-test.test.com:18122/python/test.logging_sdk.git@fxl

(base) root@sit:~/srv_code_for_docker/app/SRE/srv/SIT/CICD# python -m venv ~/sre/venv/CICD
(base) root@sit:~/srv_code_for_docker/app/SRE/srv/SIT/CICD# source ~/sre/venv/CICD/bin/activate
(CICD) (base) root@sit:~/srv_code_for_docker/app/SRE/srv/SIT/CICD# ll -as
total 32
4 drwxr-xr-x 2 root root 4096 Jul 28 16:27 ./
4 drwxr-xr-x 3 root root 4096 Jul 28 16:27 ../
0 -rw-r--r-- 1 root root 0 Jul 28 16:27 README.md
4 -rw-r--r-- 1 root root 11 Jul 28 16:27 requirements.txt
16 -rw-r--r-- 1 root root 12779 Jul 28 16:27 single.py
4 -rw-r--r-- 1 root root 451 Jul 28 16:27 webserver.py
(CICD) (base) root@sit:~/srv_code_for_docker/app/SRE/srv/SIT/CICD# which pip3
/root/sre/venv/CICD/bin/pip3
(CICD) (base) root@sit:~/srv_code_for_docker/app/SRE/srv/SIT/CICD#

原文地址:https://www.cnblogs.com/rsapaper/p/10281462.html