前言
使用python 安裝第三方包的時候,總是會因為網絡問題,導致某些依賴包安裝失敗
今天來看一下各種安裝工具(pip,pipx,poetry,easy_install)怎么更換安裝源
國內的一些鏡像
阿里雲 http://mirrors.aliyun.com/pypi/simple/
中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
PIP 更換國內安裝源
臨時使用
可以在使用pip的時候在后面加上-i參數,指定pip源
pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple
永久修改
linux
修改 ~/.pip/pip.conf (沒有就創建一個), 內容如下:
# ~/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
windows
直接在user目錄中創建一個pip目錄,如:C:\Users\xx\pip,在pip 目錄下新建文件pip.ini,內容如下
或者按照網友的建議:win+R 打開用戶目錄%HOMEPATH%,在此目錄下創建 pip 文件夾,在 pip 目錄下創建 pip.ini 文件, 內容如下
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
easy_install更換國內安裝源
創建配置文件:
Windows下是在: ~\pydistutils.cfg
Linux下是在: $HOME/.pydistutils.cfg
內容
[easy_install]
index-url=http://pypi.douban.com/simple
poetry 更換國內安裝源
poetry 使用的是配置文件安裝內容,因此在配置文件中加入下面的內容
[[tool.poetry.source]]
name = "tsinghua"
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/"
default = true # 添加一個 default 參數, 使 poetry 的默認回調行為都調用到這個清華鏡像上.