how to export django project dependency

如何导出django项目依赖第三方库

使用pip freeze 导出

针对大部分使用virtualenvvenvpipenv 虚拟环境的项目而言,导出第三方依赖很容易,运行下面的命令即可

pip freeze > requirements.txt

非虚拟环境如何导出项目依赖

安装 pipreqs

pip install pipreqs

使用

进入项目根目录,使用下面的指令

1
pipreqs ./

出现的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
D:\code\django_blog\mysite>pipreqs ./
Traceback (most recent call last):
File "c:\python38\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Python38\Scripts\pipreqs.exe\__main__.py", line 9, in <module>
File "c:\python38\lib\site-packages\pipreqs\pipreqs.py", line 470, in main
init(args)
File "c:\python38\lib\site-packages\pipreqs\pipreqs.py", line 406, in init
candidates = get_all_imports(input_path,
File "c:\python38\lib\site-packages\pipreqs\pipreqs.py", line 122, in get_all_imports
contents = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 403: illegal multibyte sequence

添加命令行参数 encoding=utf-8

1
pipreqs ./ --encoding=utf-8
坚持原创技术分享,您的支持将鼓励我继续创作!