问题描述
此类问题多见于使用远程实验室等开发环境,导致原因大多是太多人不正确地使用python内核,导致其权限与配置被弄成一团乱麻
无sudo权限的解决方法
解决方法
在每次使用pip安装包时,都采用如下命令参数后缀:
pip install {pkt_name} -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
其中{pkt_name}替换成你需要的包名,例如需要安装numpy
则执行如下命令:
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
不行就多换几个国内源,直到找到可行的为止
有sudo权限的解决方法
直接
vim ~/.pip/pip.conf
然后向文件中写入(以清华源为例,可自行更换):
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
然后按“:”+“wq”执行vim的写入并退出命令,返回终端
之后就可以快乐pip了
PS:注意使用的是pip还是pip3,针对同时装有python2.x和python3.x的开发环境