Managing and Switching PyPI Mirrors with the Oh My Zsh pypi Plugin
This guide explains how to use the Oh My Zsh pypi plugin to list, switch, and test various PyPI mirror sources, improving package download speeds for developers, especially those in mainland China, by providing simple CLI commands and connectivity checks.
Choosing an appropriate PyPI mirror can significantly improve package download speed, especially for users in China where network latency may be high. This article introduces the pypi plugin designed for Oh My Zsh users, which offers commands to list, switch, and test PyPI mirrors.
Plugin Overview
The pypi plugin is a lightweight yet powerful tool that adds a set of commands to Oh My Zsh, allowing quick switching between different PyPI mirror sources and testing their connectivity.
Installation Steps
Install via Git
Open a terminal and clone the plugin repository into the custom plugins directory of Oh My Zsh: <code>git clone https://github.com/belingud/pypi ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/pypi</code>
Edit the ~/.zshrc file and add pypi to the plugins list: <code>plugins=(... pypi ...)</code>
Save the file and reload the Zsh configuration: <code>source ~/.zshrc</code>
How to Use
After installation, the following commands are available:
List Available Mirrors
Run pypi list to display all supported PyPI mirrors and their URLs.
<code>pypi list</code>Switch to a Specific Mirror
Use pypi use <shortname> , where <shortname> is the alias of the desired mirror (e.g., aliyun for Alibaba Cloud):
<code>pypi use aliyun</code>Test Mirror Connectivity
Verify a mirror's availability with pypi ping <shortname|url> . You can provide either the alias or the full URL:
<code>pypi ping tsinghua</code>or
<code>pypi ping https://pypi.org/simple/</code>Supported Mirror List
<code>pypi: https://pypi.org/simple/
aliyun 阿里云
tencent 腾讯
huawei 华为
163 网易
volces 火山
cernet 中国教科研网校园联合镜像站
tsinghua 清华大学
sustech 南方科技大学
bfsu 北京外国语大学
nju 南京大学
dnui 大连东软信息学院
pku 北京大学
njtech 南京工业大学
nyist 南阳理工
sjtu 上海交大
zju 浙江大学
jlu 吉林大学
testpypi</code>Mirrors that are only accessible within a campus intranet are not supported.
Precautions
Ensure the short name you provide when switching mirrors is valid.
Use the ping command to check reachability before switching to a new mirror.
Getting Help
For detailed usage of each command, add -h or --help to the command, e.g.:
<code>pypi use -h</code>Conclusion
The pypi plugin makes managing and switching PyPI mirrors straightforward. For more information or issues, visit the plugin's GitHub repository.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.