1图焰、生成python項目的requeirement.txt文件
1)安裝pipreqs
pip3 install pipreqs
2)在本地生成requirements文件奥喻,這里有兩種方式
pip3 freeze > requirements.txt
pipreqs . --encoding=utf8 --force
推薦切換至需遷移項目的根目錄婉烟,使用第二種命令得湘。該命令會生成當(dāng)前項目中所有的依賴募狂,未使用的python依賴和類庫將不會被生成畜份。
PS:
1.使用第二種方式生成requirements時一定要確保項目中的所有類庫都被正確安裝了诞帐,否則pipreqs 會報錯,無法正常生成requirements文件爆雹。
2.請留意自己的python版本停蕉,一般來說python2使用pip,python3使用pip3命令钙态。
pipreqs 參數(shù):
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.
--no-pin Omit version of output packages.