首页 |  我的博客 |  查看该博主内容分类 | 

linux批量安装pip download下载的whl和tar.gz的bash脚本

脚本

python_exe="$(dirname "$1")/$(basename "$1")/bin/python"
pip_exe="$(dirname "$1")/$(basename "$1")/bin/pip"
package_dir="$(dirname "$2")/$(basename "$2")"

for file in $package_dir/*.whl ]; do
	$pip_exe install "$file" --no-deps
	if [ $? != "0" ]; then
		echo "Some error happend !"
		exit 1
	fi
done
if [ -f $package_dir/*.tar.gz ]; then
	for file in `find $package_dir -name *.tar.gz`; do
		cd $package_dir
		tar -zxvf "$file" -C /tmp -k
		cd /tmp/`basename "$file" .tar.gz`
		$python_exe setup.py install
		if [ $? != "0" ]; then
			echo "Some error happend !"
			exit 1
	done
fi
echo "Success finished packages install !"

执行命令

假如上述脚本的位置位于/opt/py_packages_install.sh
linxu执行:sh /opt/py_packages_install.sh 需要安装包的环境路径 pip下载的包的目录

  • 提示:
    需要安装包的虚拟环境路径,如:/usr/local/python3_venvs/my_project
    pip下载的包的目录,如:/usr/local/src/packages
posted @ 2023-12-15 17:51  Z哎呀  阅读(402)  评论(0)    收藏  举报