解决Python pip 安装第三方库问题

下载问题

  • 出现下载慢的问题

    • 使用国内源

    http://mirrors.aliyun.com/pypi/simple
    http://pypi.douban.com/simple
    https://pypi.tuna.tsinghua.edu.cn/simple

    python -m pip install  lxml -i https://pypi.tuna.tsinghua.edu.cn/simple 
    # 安装lxml库
    
  • 提示没有管理员权限无法安装问题

    python -m pip install --user lxml -i https://pypi.tuna.tsinghua.edu.cn/simple
    
  • 提示位于******.com的存储库不是一个受信任或安全的主机

    Collecting beautifulsoup4
    The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with ‘–trusted-host mirrors.aliyun.com’.
    Could not find a version that satisfies the requirement beautifulsoup4 (from versions: )
    No matching distribution found for beautifulsoup4

    python -m pip install --user lxml -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
    
  • 另一个一劳永逸的方法
    在C:\Users\你的用户名\目录下新建一个pip文件夹,文件夹里面新建pip.ini文件
    内容为:

    [global]
    timeout = 60000
    # index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    index-url = https://pypi.doubanio.com/simple/
    [install]
    # trusted-host=mirrors.aliyun.com
    trusted-host=pypi.douban.com
    
    

    在这里插入图片描述
    然后就可以直接使用python -m pip install lxml安装了

路径问题

  • 默认安装路径

    c:\users\你的用户名\appdata\local\programs\python\python37\lib\site-packages
    
  • 如果用pycharm新建一个项目,可能会找不到这些已安装的包。

  • 解决方法1:
    在这里插入图片描述

    • 进入这个目录M:\Projects\PycharmProject0\venv\Lib\site-packages
      在这里插入图片描述

    • 新建一个mypkpath.pth文件

    • mypkpath.pth文件里添加C:\Users\你的用户名\AppData\Local\Programs\Python\Python37\Lib\site-packages
      在这里插入图片描述

    • 这样就能找到了
      在这里插入图片描述

    • 电脑里可能有多个site-packages文件,在任意一个site-packages文件添加mypkpath.pth,都可以将其他site-packages文件里的库引用到这个文件里。

    • 解决方法2

    • 更改解释器路径

    • 在这里插入图片描述

  • 如果遇到其他问题欢迎评论区留言

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值