国内 pip 镜像源换源方法及 pip 基本操作
pip 是 Python 的包管理工具,允许用户方便地安装、升级和管理 Python 包和库。 是 Python 官方推荐的包管理工具,通常在安装 Python 时默认安装。 本文讲述国内 pip 镜像源换源方法及 pip 基本操作
https://pypi.tuna.tsinghua.edu.cn/simple
https://mirrors.aliyun.com/pypi/simple
https://pypi.douban.com/simple
https://pypi.mirrors.ustc.edu.cn/simple
https://mirrors.cloud.tencent.com/pypi/simple
注:大家根据自身需要选择合适的镜像源,个人推荐中科大的镜像源
- 使用公式
pip install 【package_name】 -i 【pip源】
注意
使用公式:
pip config set global.index-url 【pip源】
pip config list
pip config unset global.index-url
pip config unset global.index-url
pip --version
pip install --upgrade pip
pip list
注意
【package_name】为包的名字
【packetversion_id】为特定版本的包版本号
【time】为规定的时间,1秒为1,以此类推
公式:
# 安装 pip install 【package_name】 # 卸载 pip uninstall 【package_name】
安装特定版本的包
pip install 【package_name】==【packetversion_id】
例安装numpy的1.0.0版本
pip install numpy==1.0.0
遇到下载不稳定时,可以设置超时时间公式
pip install 【package_name】 --timeout 【time】
例如,安装numpy。将超时时间设置为 10 秒
pip install numpy --timeout 10
将当前环境的包导出
pip freeze > requirements.txt
从 requirements.txt 安装指定包
pip install -r requirements.txt
自定义源时的信任设置 公式
pip install 【package_name】 --trusted-host 【镜像源】
比如安装numpy且信任清华源:
pip install numpy --trusted-host pypi.tuna.tsinghua.edu.cn
ERROR: Could not find a version that satisfies the requirement …
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f4248ebf7c0>: Failed to establish a new connection: [Errno 101] 网络不可达’)':…
或者
raise ReadTimeoutError(self._pool, None, “Read timed out.”) pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Read timed out.
return self._sslobj.read(len, buffer) socket.timeout: The read operation timed out During handling of the above exception, another exception occurred: Traceback (most recent call last):…
可以尝试到官网手动下载安装: Python Package 官网
比如搜索:numpy 选择第一个
点击左侧下载,然后根据需求下载对应的 whl 文件
比如:这里选择 numpy2.2.3 ,然后python是3.10选择cp310后缀,然后是linux系统x86 架构则选择
numpy-2.2.3-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
下载完成后,到对应的环境中使用pip install 命令即可
pythonpip install xxxxx.whl
本文作者:Dageling003
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!