【Python】Linux、Windows更换镜像源(pip、conda、pycharm)

“pip” 更换镜像源

临时使用

可以在使用pip的时候加参数-i 镜像地址

国内源

新版ubuntu要求使用https源。

举例:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas

python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip

这样就会从清华这边的镜像去安装pandas库。

永久修改

Linux

修改 ~/.pip/pip.conf (Linux系统,没有就创建一个文件夹及文件)

[global] 
timeout = 60000
index-url = http://mirrors.aliyun.com/pypi/simple/ 
[install] 
trusted-host=mirrors.aliyun.com 

windows

1、WIN+R,然后输入%APPDATA%,会定位到一个新的目录下,我的是

C:\Users\Administrator\AppData\Roaming

2、在该目录下新建pip文件夹

3、然后到pip文件夹里面去新建个pip.ini文件

4、然后打开该文件,将以下内容写入进去

[global]
timeout = 6000
index-url = http://pypi.douban.com/simple
[install] 
trusted-host = pypi.douban.com

“conda” 更换镜像源

终端输入

conda
conda config --show-sources
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

“pycharm” 更换镜像源

File >Settings > Project: [项目名] > Project Interpreter > [右边加号] 
> Manager Repositories > [右边加号] > 输入  http://mirrors.aliyun.com/pypi/simple/ 

批量部署

python中通过requirements.txt来记录项目所有的依赖包及其版本号,以便在其他的环境中部署

python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip

pip freeze > requirements.txt

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt

镜像地址

机构镜像地址
阿里云http://mirrors.aliyun.com/pypi/simple/
豆瓣http://pypi.douban.com/simple/
清华https://pypi.tuna.tsinghua.edu.cn/simple
中国科技大学https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学http://pypi.hustunique.com/
山东理工大学http://pypi.sdutlinux.org/

Python 安装路径

import sys 
sys.executable
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值