问题描述:
win+R,打开cmd窗口,输入命令:
pip install lxml
得到报错:
Defaulting to user installation because normal site-packages is not writeable
问题原因:
查询后得知,是因为我的Python的库和Python都安装在C盘的Program Files文件夹下。
但是,这个文件夹里做任何修改都需要管理员权限。
所以,应当在打开cmd的时候就用管理员权限打开,即:
然后重新输入命令:
pip install lxml
得到提示:
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Requirement already satisfied: lxml in c:\anaconda\lib\site-packages (4.8.0)
问题原因:
因为我的电脑装了多个Python版本和虚拟环境,pip不确定要将包安装在哪个环境中。
解决方法:
明确指定Python解释器的位置来安装包,即:告诉pip应该安装在哪个地方。
使用-m参数来指定Python解释器的位置
-m pip install --user haversine -i https://pypi.doubanio.com/simple/
成功安装,问题解决√
- 注:可以使用国内镜像源提高下载速度。
阿里云:http://mirrors.aliyun.com/pypi/simple
清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
豆瓣:http://pypi.douban.com/simple