建立网站需要投入的成本网站有订单了有声音提醒怎么做
目录
- pip 换源
 - 相关命令
 - 永久换源
 - 1. 命令行换源
 - 2. 配置文件换源
 
- 临时换源
 - 使用官方源
 - 使用镜像源
 
- 报错参考
 
- npm换源
 - 相关命令
 - 永久换源
 - 1. 命令行换源
 - 2. 配置文件换源
 
pip 换源
相关命令
- 更新 pip 本身
 
首先,为了确保你使用的是最新版本的 pip,可以通过以下命令更新:
pip install --upgrade pip
 
- 查看当前镜像源
 
使用以下命令查看当前设置的镜像源:
pip config list
 
永久换源
你可以选择通过命令行或配置文件来永久切换 pip 的镜像源。
1. 命令行换源
使用以下命令永久切换 pip 的镜像源为清华大学的镜像源:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
 
2. 配置文件换源
在路径 C:\Users\<YourUsername>\AppData\Roaming\pip 目录下创建 pip.ini 文件,并添加以下内容:
[global]
timeout = 6000
index-url = https://mirrors.aliyun.com/pypi/simple/[install]
trusted-host = mirrors.aliyun.com
 
timeout = 6000:设置超时,防止网络不稳定时导致下载失败。index-url:设置镜像源的 URL,建议使用阿里云或清华大学的镜像源。trusted-host:设置可信任的主机,避免 SSL 证书验证错误。
临时换源
如果你仅需要临时使用不同的源进行安装,可以使用 -i 选项指定镜像源。
使用官方源
如果你之前切换到了国内源,并且在安装某些工具时遇到问题,可以临时切换回官方源:
pip install <package-name> -i https://pypi.org/simple
 
使用镜像源
对于大多数用户,使用清华大学的镜像源可以显著提高下载速度。你可以通过以下命令安装包:
pip install <package-name> -i https://pypi.tuna.tsinghua.edu.cn/simple
 
报错参考
如果在使用 pip 安装过程中遇到报错(例如:externally-managed-environment 错误),可以参考我写的以下文章,获取解决方案:Kali Linux 最新版本下无法直接 pip 安装?教你三招完美解决‘externally-managed-environment’报错!
npm换源
相关命令
- 查看当前 npm 镜像源
 
要查看当前设置的 npm 镜像源,可以使用以下命令:
npm config get registry
 
- 更新 npm
 
为了确保你使用的是最新版本的 npm,可以通过以下命令更新 npm:
npm i -g npm
 
永久换源
你可以通过命令行永久更换 npm 的镜像源。以下是官方源和常见的国内镜像源:
- npm 官方源:registry.npmjs.org
 - 最新的淘宝镜像源:registry.npmmirror.com
 - 以前的淘宝镜像源:https://registry.npm.taobao.org
 - 腾讯云镜像源:mirrors.cloud.tencent.com/npm
 
1. 命令行换源
使用以下命令永久切换到 npm 淘宝镜像源:
 npm config set registry https://registry.npmmirror.com
 
2. 配置文件换源
npm 的配置文件通常位于 ~/.npmrc(Windows 系统位于 C:\Users\<YourUsername>\.npmrc)中。你可以手动编辑该文件,添加以下内容来更换镜像源:
registry=https://registry.npmmirror.com
 
我的配置文件如下:
prefix=D:\Dev\nodejs\node_global
cache=D:\Dev\nodejs\node_cache
registry=https://registry.npmjs.org/
