pip换源+更改默认安装位置

本文档创建于2023年3月9日

本文记录了pip换源和更改默认安装位置的操作。主要用于pip的一些配置,方便下载和文件管理

pip换源

使用pip安装库时,如果用默认的库经常会遇到连接不上或下载慢的问题,更换为国内的库下载会更快。

临时换源

安装命令后加-i url,例如:

pip install PyQt6 -i https://pypi.tuna.tsinghua.edu.cn.simple/

永久替换

用pip命令设置pip国内源:

#先更新一下pip版本
python -m pip install pip -U #-i https://pypi.tuna.tsinghua.edu.cn/simple/
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
pip config set install.trusted-host https://pypi.tuna.tsinghua.edu.cn

更改pip默认安装位置

在windows下使用pip时,默认安装位置在C盘。为了不占用C盘空间,我们可以修改默认安装位置。

打开终端,先查看当前安装位置:

python -m site

在这里插入图片描述

USER_BASE和USER_SITE显示了现在的安装位置

查找存放USER_BASE和USER_SITE的文件:

python -m site -help

在这里插入图片描述

打开显示的site.py文件:
在这里插入图片描述

修改USER_BASE和USER_SITE:

USER_SITE = "D:\software\\anaconda3\Lib\site-packages"
USER_BASE = "D:\software\\anaconda3\Scripts"

保存之后再次打开终端,输入python -m site,显示的USER_BASE和USER_SITE发生了改变,修改成功:

在这里插入图片描述

需要注意的是,修改了默认安装位置之后,在安装包时可能会出现如下报错:

ERROR: Could not install packages due to an OSError: [WinError 5] 拒绝访问。: ‘d:\software\visualstudioshared\python39_64\lib\site-packages\pip-22.3.1.dist-info\entry_points.txt’ Check the permissions.

s\pip-22.3.1.dist-info\entry_points.txt’ Check the permissions.

这个是由于访问权限不够导致安装不成功,只要以管理员身份运行cmd(PowerShell)即可。

猜你喜欢

转载自blog.csdn.net/svfsvadfv/article/details/129419604
今日推荐