你可以使用 pip 进行安装:
(base) C:\WorkDir\Ossez-Com\Python\Source-Code\python-tutorials>pip install pipreqs
你的控制台输出为:
(base) C:\WorkDir\Ossez-Com\Python\Source-Code\python-tutorials>pip install pipreqs
Collecting pipreqs
Downloading pipreqs-0.4.10-py2.py3-none-any.whl (25 kB)
Collecting yarg
Downloading yarg-0.1.9-py2.py3-none-any.whl (19 kB)
Collecting docopt
Downloading docopt-0.6.2.tar.gz (25 kB)
Requirement already satisfied: requests in c:\users\yhu\anaconda3\lib\site-packages (from yarg->pipreqs) (2.22.0)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\yhu\anaconda3\lib\site-packages (from requests->yarg->pipreqs) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\yhu\anaconda3\lib\site-packages (from requests->yarg->pipreqs) (2019.11.28)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\yhu\anaconda3\lib\site-packages (from requests->yarg->pipreqs) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\yhu\anaconda3\lib\site-packages (from requests->yarg->pipreqs) (1.25.8)
Building wheels for collected packages: docopt
Building wheel for docopt (setup.py) ... done
Created wheel for docopt: filename=docopt-0.6.2-py2.py3-none-any.whl size=13709 sha256=a21459d10457e230e3c60e6166fa71ddcdd7f816be14feb371b6dbebad5d47a0
Stored in directory: c:\users\yhu\appdata\local\pip\cache\wheels\72\b0\3f\1d95f96ff986c7dfffe46ce2be4062f38ebd04b506c77c81b9
Successfully built docopt
Installing collected packages: yarg, docopt, pipreqs
Successfully installed docopt-0.6.2 pipreqs-0.4.10 yarg-0.1.9
(base) C:\WorkDir\Ossez-Com\Python\Source-Code\python-tutorials>
下图是安装的控制台输出。
安装完成后,你可以校验安装。
在你的当前项目中运行
(base) C:\WorkDir\Ossez-Com\Python\Source-Code\python-tutorials>pipreqs . --force
这里有参数是 --force,主要是针对当前你项目中已有的依赖约束文件,你需要进行强制创建。
注意 pipreqs 后面有个 . 号。
在你的控制台中,将会输出:
(base) C:\WorkDir\Ossez-Com\Python\Source-Code\python-tutorials>pipreqs . --force
INFO: Successfully saved requirements file in .\requirements.txt
控制台输出如下:
同时你会看到你的约束只有你项目真正需要的,而不会将你环境中所有的约束全部创建。
如上图,程序就清爽很多了。


