import os
source = "http://mirrors.aliyun.com/pypi/simple/"
source_trusted = "mirrors.aliyun.com "
config = "[global]\nindex-url = " + source + "\n[install]\ntrusted-host=" + source_trusted
#pip_path = os.environ["USERPROFILE"] + "\\pip\\" #%APPDATA%
pip_path = os.environ["APPDATA"] + "\\pip\\"
print(pip_path)
if not os.path.exists(pip_path):
os.makedirs(pip_path)
print('%APPDATA%目录建立pip目录')
with open(pip_path + "pip.ini", "w+") as f:
f.write(config)
print(config)
新建一个.py文件,将上述代码拷贝,然后运行该.py文件,简单高效!