python 换 豆瓣源 - 直接运行Python代码即可
- Windows 版
import os
path = os.getenv('APPDATA') #获取环境变量
data = """[global]
timeout = 6000
index-url = http://pypi.douban.com/simple/
trusted-host = pypi.douban.com
"""
# 写入的数据
folder_path = os.path.join(path, "pip")
file_path = os.path.join(path, "pip", "pip.ini")
print(file_path)
folder = os.path.exists(folder_path) #判断文件夹是否存在
if not folder:
os.mkdir(folder_path) #创建文件夹
f = open(file_path, 'w') #写文件
f.write(data)
f.close()
- Linux 版
cd $home
mkdir .pip
cd .pip
touch pip.conf
把下面代码复制进 pip.conf 文件中
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
标签:douban,Windows,pypi,python,Linux,pip,path,folder,os From: https://www.cnblogs.com/harlanlu/p/17320186.html