腾讯云服务器通过pip安装librosa时报错distutils.errors.DistutilsError

WARNING: This article may be obsolete
This post was published in 2020-09-29. Obviously, expired content is less useful to users if it has already pasted its expiration date.

有的时候在新创建的anaconda env里执行pip install librosa,会出现来自腾讯云内部设置镜像源带来的pip源错误:

distutils.errors.DistutilsError: Command '['/root/anaconda3/envs/python38_envs/bin/python', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmpu_wmfoov', '--quiet', --index-url', 'http://mirrors.tencentyun.com/pypi/simple', 'pytest-runner']' returned non-zero exit status 1.

这个问题有的时候容易造成一些困扰:明明已经设置了 pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple 作为默认镜像源,但还是会出现http://mirrors.tencentyun.com/pypi/simple相关的报错。

下面是我的解决办法:

腾讯云提供的一系列linux发行版系统(centOS、ubuntu、Debian等等),里面的各种镜像配置文件都被修改成了mirrors.tencentyun.com(这个地址需要配置腾讯云内网dns才能访问,里面有很多镜像源早已废弃),包括pypi、yum、apt、deb等等。

pip有多个配置文件,根据https://pip.pypa.io/en/stable/topics/configuration/列举的配置文件逐一搜索腾讯云的硬盘可以发现,腾讯云在镜像刚刚安装的时候就配置了一个 /root/.pip/pip.conf 文件,优先级排在默认的 /root/.config/pip/pip.conf 之后;此外,还有一个 .pydistutils.cfg 文件,里面也写入了mirrors.tencentyun.com作为镜像源:

root$ cat /root/.pip/pip.conf
[global]
index-url = http://mirrors.tencentyun.com/pypi/simple
trusted-host = mirrors.tencentyun.com

root$ cat /root/.config/pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

root$ cat /root/.pydistutils.cfg
[easy_install]
index-url = http://mirrors.tencentyun.com/pypi/simple

所以最省事的方法是直接删除 /root/.pip 文件夹和 /root/.pydistutils.cfg 文件。

如果不删除以上文件,也可以使用easy_install绕开pip安装出现的问题(不一定100%可行):

$    easy_install -i https://pypi.tuna.tsinghua.edu.cn/simple librosa

 Last Modified in 2023-04-18 


Leave a Comment Anonymous comment is allowed / 允许匿名评论