Koa2设置路径别名,使用@或者~来指定路径文件

青禾大神
常见问题
发布于 2025-04-28
16 阅读
23 评论
2.4k 点赞
#Koa2 #Nuxt3 #NodeJs

方法 1:临时使用镜像源(单次下载)

pip install 命令后直接指定镜像源 URL(以清华源为例):

bash 复制代码
pip install [包名] -i https://pypi.tuna.tsinghua.edu.cn/simple/

例如安装 numpy

bash 复制代码
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/

注意事项:

  • 若遇到 SSL 证书验证问题,可添加 --trusted-host 参数:
bash 复制代码
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn

方法 2:永久配置镜像源(推荐)

修改 pip 的全局配置文件,避免每次手动指定源。

步骤:

  1. 创建或修改配置文件
  • Windows
    在文件资源管理器地址栏输入 %APPDATA%,进入该目录后创建 pip 文件夹,并在其中创建 pip.ini 文件,内容如下:
ini 复制代码
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
trusted-host = pypi.tuna.tsinghua.edu.cn
  • Linux/MacOS
    在终端中执行以下命令:
bash 复制代码
mkdir -p ~/.pip
echo -e "[global]\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple/\ntrusted-host = pypi.tuna.tsinghua.edu.cn" > ~/.pip/pip.conf
  1. 验证配置
    运行以下命令查看当前配置:
bash 复制代码
pip config list

输出应包含:

复制代码
global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple/'

其他镜像源替换

将上述配置中的 index-url 替换为其他镜像源地址即可:

  • 阿里云http://mirrors.aliyun.com/pypi/simple/
  • 中科大http://pypi.mirrors.ustc.edu.cn/simple/
  • 华为云https://repo.huaweicloud.com/repository/pypi/simple/

首次安装 pip(若未安装)

如果系统未安装 pip,可下载 get-pip.py 并通过镜像源安装:

bash 复制代码
# 下载安装脚本
curl -O https://bootstrap.pypa.io/get-pip.py

# 使用清华源安装 pip
python get-pip.py -i https://pypi.tuna.tsinghua.edu.cn/simple/

升级 pip 至最新版

bash 复制代码
pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple/

通过上述配置,pip 将默认使用国内镜像源,大幅提升下载速度并避免网络问题。

青禾大神

Vue技术专家 | 5年开发经验

专注前端技术领域,Vue生态贡献者,定期分享前沿技术文章。

评论 (128)

前端小白

这篇文章讲得太好了,解决了我很多疑惑!

资深开发者

对依赖收集部分的讲解很深入,期待更多原理分析文章!

相关推荐

Vue3组合式API最佳实践

3.2k阅读 · 86评论

Pinia状态管理深度解析

2.5k阅读 · 45评论