pip freeze
包含了當前環境所包含的全部依賴包資訊,影響復現者對主次依賴的判斷;export yml
通過建立 yaml 文字實現環境打包,包含 pip
指定包安裝及相關依賴資訊,但存在跨平臺問題;--from-history
等 flag 都旨在解決相關問題;根據實際的包安裝過程生成一種具有高可讀性的 requirements.txt
環境依賴包文字,嚴格按照安裝先後 先後排序,只列舉指定安裝包及其版本資訊。
通過自定義 pip-install
及 pip-uninstall
shell command 替代原有的 pip install/uninstall
安裝包工作流,並對 requirements.txt
進行同步更新:
pip-install
command (BSD & GNU)function pip-install() {
# loop through all listed requirements
for var in "$@"
do
# attempt to install it
pip install $var
# add it to the requirements.txt file
pip freeze | grep -i "^$var=" >> requirements.txt
done
# remove duplicates in the requirements.txt
awk -i inplace '!a[$0]++' requirements.txt
}
pip-uninstall
command (GNU請先閱讀)function pip-uninstall() {
for var in "$@"
do
pip uninstall $var
# for macOS (BSD Unix)
# for GNU distribution using sed instead.
gsed -i "/$var==./d" requirements.txt
# i.e. GNU: sed -i ...
done
}
~/.zshrc
或 ~/.bashrc
組態檔;source
組態檔;terminal
進行測試:$ pip-install/pip-uninstall
;