第三方模块是由全球Python爱好者、程序员、各行各业的专家进行开发并进行维护。
安装第三方模块语法
pip install 模块名称
如果您还没有安装pip,请先通过Homebrew安装pip:
brew install pip
在Mac上,您可以通过以下命令安装,我用的是Python 3.13,所以用pip3开始:
pip3 install requests
其他常见国内镜像源安装
网络不好安装国外镜像源失败的,可以使用国内的镜像源安装requests:
使用 pip3
从 豆瓣 PyPI 镜像源 安装 Python requests库
pip3 install requests -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
如果豆瓣源不可用,可以换成:
-
清华大学(推荐,支持 HTTPS)
pip3 install Matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
-
阿里云
pip3 install Matplotlib -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
-
中科大
pip3 install Matplotlib -i https://pypi.mirrors.ustc.edu.cn/simple
命令部分 | 作用 |
---|---|
pip3 install Matplotlib | 安装 Matplotlib 库 |
-i http://pypi.douban.com/simple | 使用豆瓣 PyPI 镜像加速下载 |
--trusted-host pypi.douban.com | 信任该镜像(避免 HTTP 安全警告) |
如果遇到问题,可以尝试:
-
升级 pip:
pip3 install --upgrade pip
-
换镜像源(如清华、阿里云)
-
检查网络(是否被防火墙/代理阻止)
卸载第三方模块的语法结构
pip uninstall 模块名称
卸载requests库
pip3 uninstall requests
升级pip命令的语句结构
python -m pip install --upgrade pip