1. Windows 安装 Python
打开 Python 官方 Windows 下载页面,按照官方说明安装 Python 3。
安装完成后打开 PowerShell:
python --version能够看到 Python 3 的版本号即可。
检查 pip
python -m pip --version以后安装 Python 软件包可以使用:
python -m pip install PACKAGE_NAME2. macOS 安装 Python
打开 Python 官方 macOS 下载页面,下载并安装 Python 3。
安装完成后打开 Terminal:
python3 --version检查 pip:
python3 -m pip --version3. Linux 安装 Python
先检查系统是否已经安装 Python 3:
python3 --version
python3 -m pip --versionDebian / Ubuntu
sudo apt update
sudo apt install python3 python3-pip安装后再次检查:
python3 --version
python3 -m pip --version4. 国内 pip 下载慢:使用清华 PyPI 镜像
临时使用镜像安装软件包:
Windows
python -m pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple PACKAGE_NAMEmacOS / Linux
python3 -m pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple PACKAGE_NAME需要长期使用时,可以设为默认源。
Windows
python -m pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simplemacOS / Linux
python3 -m pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple查看当前配置:
python3 -m pip config list5. 使用中科大 PyPI 镜像
清华镜像访问不理想时,也可以使用中科大镜像:
python3 -m pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/simpleWindows 将 python3 换成 python。
6. 恢复官方 PyPI
Windows
python -m pip config unset global.index-urlmacOS / Linux
python3 -m pip config unset global.index-url7. pip 无法使用
如果出现 No module named pip,可以尝试:
Windows
python -m ensurepip --default-pipmacOS / Linux
python3 -m ensurepip --default-pipLinux 如果出现 externally-managed-environment,不要直接使用 --break-system-packages 修改系统 Python。