python导出依赖,记录下坑

工具:pipreqs,可以一个命令行直接生成项目中import导入的依赖清单requirements.txt

安装:

pip install pipreqs

项目目录下导出依赖:

pipreqs ./

如果window下报编码错误'gbk' codec can't decode byte 0x9a in position 13: illegal multibyte sequence,使用encoding参数

pipreqs ./ --encoding=utf-8  # 带中横线 “-”

注意:不知道别人什么情况,我是用utf8不行,提示 usage: pipreqs [options] [<path>],换成utf-8,中间加个中横线就行(坑)

更新: utf8写法又可以了,不知道啥原因,确定命令没有拼错

pip3 install -r requirements.txt

# 阿里云加速
pip3 install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com  -r requirements.txt

pip导出依赖

此方式会导出所有的第三方依赖 以及 依赖的依赖

pip freeze >requirements.txt

虚拟环境:

安装(ubuntu)

sudo apt install python3-venv

创建虚拟环境

python3 -m venv venv

 激活虚拟环境

source venv/bin/activate

退出

deactivate
原文地址:https://www.cnblogs.com/zhzhlong/p/13292773.html