Python生成requirements.txt的两种方式

方式一(适合在使用单虚拟环境venv时使用)

  • 该种方式会将环境中所有的依赖包全部加入。
pip freeze > requirements.py

方式二(使用全局环境时,该种方式最合适)

# 首先需要保证安装了pipreqs模块
pip install pipreqs
# 在当前目录生成依赖文件
pipreqs . --encoding=utf-8 --force
  • –encoding=utf8 表示使用utf8编码,不然可能会报UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xae in position 406: illegal multibyte sequence 的错误。
  • –force 表示强制执行,当前目录下原本已有的requirements.txt会被覆盖。

补充(使用requirements.txt安装依赖)

pip insatll -r requirements.txt

参考文章:https://blog.csdn.net/z13653662052/article/details/105602718/

猜你喜欢

转载自blog.csdn.net/ungoing/article/details/124759673