任意文件夹下新建个xxx.sh,把下面的内容敲进去
#!/bin/bash
echo "pip换源"
cd ~
dir=".pip"
[ -d "$dir" ] && rm -rf "$dir"
mkdir "$dir"
cat>"$dir"/pip.conf<<EOF
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF
然后运行
sh ./xxx.sh
就行了