Ubuntu 之更换与使用apt源和p

发布时间:2019-10-15 09:04:54编辑:auto阅读(1881)

    Ubuntu 之更换与使用apt源和python源.md

    一键更换脚本内容

    #! /bin/bash
    echo "设置浙大镜像源"
    (cat << EOF
    deb http://mirrors.zju.edu.cn/ubuntu xenial main universe restricted multiverse
    deb http://mirrors.zju.edu.cn/ubuntu xenial-security main universe restricted multiverse
    deb http://mirrors.zju.edu.cn/ubuntu xenial-updates main universe restricted multiverse
    deb http://mirrors.zju.edu.cn/ubuntu xenial-backports main universe restricted multiverse
    deb-src http://mirrors.zju.edu.cn/ubuntu xenial main universe restricted multiverse
    deb-src http://mirrors.zju.edu.cn/ubuntu xenial-security main universe restricted multiverse
    deb-src http://mirrors.zju.edu.cn/ubuntu xenial-updates main universe restricted multiverse
    deb-src http://mirrors.zju.edu.cn/ubuntu xenial-backports main universe restricted multiverse
    EOF
    ) | sudo tee /etc/apt/sources.list
    echo "写入浙大Ubuntu16.04 amd64 apt镜像源完成"
    sudo apt update
    
    
    echo "现在开始修改Python的Zju pipy源:"
    cd ~
    mkdir .pip
    cd .pip
    (cat << EOF
    index-url=http://mirrors.zju.edu.cn/pypi/web/simple
    trusted-host=mirrors.zju.edu.cn
    disable-pip-version-check =true
    EOF
    ) | sudo tee ~/.pip/pip.conf
    echo "更换成Zju Pipy源完成"
    echo "注意如果需要安装Python3的安装包,请使用以下命令:python3 -m pip install numpy"
    echo "注意如果需要安装Python2的安装包,请使用以下命令:python2 -m pip install numpy"
    echo "不建议大家直接用pip install的方式安装python包,这样你会不清楚装的是python2的包还是python3的包"

    修改Ubuntu apt源

    打开/etc/apt/sources.list文件,删除里面所有内容,添加以下内容进去,保存即可。

    deb http://mirrors.zju.edu.cn/ubuntu xenial main universe restricted multiverse
    deb http://mirrors.zju.edu.cn/ubuntu xenial-security main universe restricted multiverse
    deb http://mirrors.zju.edu.cn/ubuntu xenial-updates main universe restricted multiverse
    deb http://mirrors.zju.edu.cn/ubuntu xenial-backports main universe restricted multiverse
    deb-src http://mirrors.zju.edu.cn/ubuntu xenial main universe restricted multiverse
    deb-src http://mirrors.zju.edu.cn/ubuntu xenial-security main universe restricted multiverse
    deb-src http://mirrors.zju.edu.cn/ubuntu xenial-updates main universe restricted multiverse
    deb-src http://mirrors.zju.edu.cn/ubuntu xenial-backports main universe restricted multiverse

    注意:
    这种方式修改的apt源,对同系统所有用户都有效

    修改Ubunt 的Python 源

    在用户自己主目录下面,先新建文件夹.pip,然后在.pip文件夹下创建名为pip.conf的文件。其文件内容如下:最后保存即可。

    [global]
    index-url=http://mirrors.zju.edu.cn/pypi/web/simple
    trusted-host=mirrors.zju.edu.cn
    disable-pip-version-check =true

    注意:
    这种形式修改的pipy源只对当前用户生效。
    不推荐用户直接使用pip install的方式安装包(容易不清楚安装的是python3还是python2的包)。
    推荐使用以下命令安装python包:

    注意如果需要安装Python3的安装包,请使用以下命令:python3 -m pip install numpy***
    注意如果需要安装Python2的安装包,请使用以下命令:python2 -m pip install numpy***

关键字