首页>文档>一键脚本>Windows&Linux一键切换pip源

需要支持?

如果通过文档没办法解决您的问题,请提交工单获取我们的支持!

Windows&Linux一键切换pip源

我对一键脚本这种东西非常感兴趣,因为快。

这是在linux下设置一键切换pip源

#!/bin/bash

echo "请选择pip源:"
echo "1. 默认源"
echo "2. 豆瓣源"
echo "3. 清华源"

read -p "请输入数字选择源(1/2/3): " source_index

if [ $source_index == 1 ]; then
    source_url="https://pypi.org/simple"
elif [ $source_index == 2 ]; then
    source_url="https://pypi.douban.com/simple"
elif [ $source_index == 3 ]; then
    source_url="https://pypi.tuna.tsinghua.edu.cn/simple"
else
    echo "输入错误,请重新输入"
    exit 1
fi

echo "正在设置pip源..."

mkdir -p ~/.pip

echo "[global]
index-url = $source_url
trusted-host = pypi.douban.com
           pypi.org
           pypi.tuna.tsinghua.edu.cn" > ~/.pip/pip.conf

echo "pip源设置完成!"

这是在windows下一键切换pip源:

@echo off

echo 请选择pip源:
echo 1. 默认源
echo 2. 豆瓣源
echo 3. 清华源

set /p source_index=请输入数字选择源(1/2/3): 

if "%source_index%" == "1" (
    set source_url=https://pypi.org/simple
) else if "%source_index%" == "2" (
    set source_url=https://pypi.douban.com/simple
) else if "%source_index%" == "3" (
    set source_url=https://pypi.tuna.tsinghua.edu.cn/simple
) else (
    echo 输入错误,请重新输入
    exit /b
)

echo 正在设置pip源...

mkdir %UserProfile%\pip

echo [global] > %UserProfile%\pip\pip.ini
echo index-url = %source_url% >> %UserProfile%\pip\pip.ini
echo trusted-host = pypi.douban.com >> %UserProfile%\pip\pip.ini
echo           pypi.org >> %UserProfile%\pip\pip.ini
echo           pypi.tuna.tsinghua.edu.cn >> %UserProfile%\pip\pip.ini

echo pip源设置完成!
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索