Recently finished writing automation scripts, found the time to share with colleagues difficult to resolve dependencies (not virtualenv use). I want to see it open interface platform projects before when you can one-click download dependencies, so he found a third-party packages pipreqs, can automatically help us to automatically generate requirements.txt
- github original introduction: pipreqs- generate pip requirements.txt file based import any item
Links: https://github.com/bndr/pipreqs
Step One: Download pipreqs Kit (pip install pipreqs)
Microsoft Windows [版本 10.0.17134.1069]
(c) 2018 Microsoft Corporation。保留所有权利。
C:\Users\wy.DESKTOP-KENPKKP\Desktop\Dingda\dingAPI>pip install pipreqs
Collecting pipreqs
Downloading https://files.pythonhosted.org/packages/f8/8d/2e7c15bc5fcab54f9c5b404b5668fdac65f5e3224b2116097fae1299fc98/pipreqs
-0.4.9-py2.py3-none-any.whl
Collecting docopt
Downloading https://files.pythonhosted.org/packages/a2/55/8f8cab2afd404cf578136ef2cc5dfb50baa1761b68c9da1fb1e4eed343c9/docopt-
0.6.2.tar.gz
Collecting yarg
Downloading https://files.pythonhosted.org/packages/8b/90/89a2ff242ccab6a24fbab18dbbabc67c51a6f0ed01f9a0f41689dc177419/yarg-0.
1.9-py2.py3-none-any.whl
Installing collected packages: docopt, yarg, pipreqs
Running setup.py install for docopt ... done
Successfully installed docopt-0.6.2 pipreqs-0.4.9 yarg-0.1.9
Second step: switch to the next item path, generating a txt file dependencies (pipreqs ./ --encoding = utf8)
During encountered an error: coding errors (UnicodeDecodeError: 'gbk' codec can not decode byte 0x95 in position 40)
C:\Users\wy.DESKTOP-KENPKKP\Desktop\Dingda\dingAPI>pipreqs ./
Traceback (most recent call last):
File "c:\users\wy.desktop-kenpkkp\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
......
extra_ignore_dirs=extra_ignore_dirs)
File "c:\users\wy.desktop-kenpkkp\appdata\local\programs\python\python36\lib\site-packages\pipreqs\pipreqs.py", line 75, in ge
t_all_imports
contents = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x95 in position 40: illegal multibyte sequence
Find the reason for this is because in Windows the need for coding is: uft-8, as follows
C:\Users\wy.DESKTOP-KENPKKP\Desktop\Dingda\dingAPI>pipreqs ./ --encoding=utf8
INFO: Successfully saved requirements file in ./requirements.txt
Step 3: Check the required dependencies (type requirements.txt)
C:\Users\wy.DESKTOP-KENPKKP\Desktop\Dingda\dingAPI>type requirements.txt
requests==2.18.4
xlutils==2.0.0
xmltodict==0.12.0
xlrd==1.2.0
dicttoxml==1.7.4
The method of downloading dependencies (pip install -r requriements.txt)
C:\Users\wy.DESKTOP-KENPKKP\Desktop\Dingda\dingAPI>pip install -r requirements.txt
Requirement already satisfied: requests==2.18.4 in c:\users\wy.desktop-kenpkkp\appdata\local\programs\python\python36\lib\site-p
ackages (from -r requirements.txt (line 1)) (2.18.4)
Requirement already satisfied: xlutils==2.0.0 in c:\users\wy.desktop-kenpkkp\appdata\local\programs\python\python36\lib\site-pac
kages (from -r requirements.txt (line 2)) (2.0.0)
Requirement already satisfied: xmltodict==0.12.0 in c:\users\wy.desktop-kenpkkp\appdata\local\programs\python\python36\lib\site-
packages (from -r requirements.txt (line 3)) (0.12.0)
Requirement already satisfied: xlrd==1.2.0 in
Detailed usage comes pipreqs
gitbug Address: https://github.com/bndr/pipreqs
- usage:
pipreqs [选项] <路径>
- Options:
- use-local package using only local information instead of querying PyPI
- pypi-server
Use custom server PyPi - proxy
Using a proxy, parameters are passed to the database request. You can also set the parameters of the terminal in the only environment: - $ export HTTP_PROXY =“ http://10.10.1.10:3128”
- $ export HTTPS_PROXY =“ https://10.10.1.10:1080”
- debug Print debugging information
- ignore <directory> ... ignores the extra directory
- encoding
Open the file using the encoding parameters - savepath <file> wanted list stored in the given file
- print output list of requirements in the standard output
- force overwrite the existing requirements.txt
- clean <file> to clean up requirements.txt module by deleting items are not imported.