pip相关工具使用小结
最近写taffy的时候用到了两个pip相关的小工具。
一个是pip-review批量更新lib库,一个是pipreqs生成基于项目的requirements.txt。
1. pip相关命令
#更新单个lib(不能批量更新) $ pip install --upgrade xxx #生成全部requirements.txt(不能基于项目生成) $ pip freeze > requirements.txt
2. pip-review
github地址:https://github.com/jgonggrijp/pip-review
使用pip install直接安装即可:
$ pip install pip-review
基本使用方法:
#查看可更新lib $ pip-review #自动批量升级lib $ pip-review --auto #以交互方式运行,对每个包进行升级 $ pip-review --interactive
3. pipreqs
github地址:https://github.com/bndr/pipreqs
同样使用pip install命令安装即可:
$ pip install pipreqs
用法:
Usage: pipreqs [options] <path> Options: --use-local Use ONLY local package info instead of querying PyPI --pypi-server <url> Use custom PyPi server --proxy <url> Use Proxy, parameter will be passed to requests library. You can also just set the environments parameter in your terminal: $ export HTTP_PROXY="http://10.10.1.10:3128" $ export HTTPS_PROXY="https://10.10.1.10:1080" --debug Print debug information --ignore <dirs>... Ignore extra directories --encoding <charset> Use encoding parameter for file open --savepath <file> Save the list of requirements in the given file --print Output the list of requirements in the standard output --force Overwrite existing requirements.txt --diff <file> Compare modules in requirements.txt to project imports. --clean <file> Clean up requirements.txt by removing modules that are not imported in project.
示例:
#生成location项目requirements.txt $ pipreqs /home/project/location Successfully saved requirements file in /home/project/location/requirements.txt #覆盖生成requirements.txt $ pipreqs --force /home/project/location