摘要

Python具有非常强大的第三方库,它可以帮助你处理各种工作,包括正则表达式、文档生成、单元测试、线程、数据库、网页浏览器、CGI、FTP、电子邮件、XML、XML-RPC、HTML、WAV文件、密码系统、GUI(图形用户界面)、Tk和其他与系统有关的操作。
而要想在自己代码中调用这些第三方库,首先需要提前安装。一般可以打开cmd,在命令提示符中输入安装指令。安装过程往往会因为网络,版本等各种问题,而导致安装失败。下面我讲介绍几种安装方法,合理运用这几种方法能够解决大部分安装问题。

安装方法

以安装fake_useragent为例

  1. 第一种:
    pip install fake_useragent

这种是最简单的安装方法,然而因为默认镜像源访问速度过慢,在国内经常会因为超时从而导致更新和下载失败。

  1. 第二种:
    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple fake_useragent
从清华大学开源软件镜像站上下载安装第三方库

通过cmd安装python3.9 怎么在cmd中下载安装python的库_windows

  1. 第三种:
    C:\Users\Administrator>D:D:\>CD D:\projectD:\project>pip install fake_useragent.whl

这种方法是安装一些特殊的第三方库,或者是特定版本的第三方库。首先去各种镜像源网站或者自行找资源下载该.whl文件
比如下载到了D:\project\fake_useragent-0.1.11.whl
在命令提示符中进入下载目录D:\project
通过pip install 文件名来安装该库

  1. 第四种:
    更改默认镜像源

在用户根目录文件夹内找到.condarc文件,打开,编辑为以下内容。这样就可以把默认镜像源改为清华开源镜像,之后的第三方库就可以直接用第一张方法安装。
pip install fake_useragent

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

通过cmd安装python3.9 怎么在cmd中下载安装python的库_通过cmd安装python3.9_02

查看与卸载方法

  1. 查看
    查看是否安装了某第三方库,及其版本pip show fake_useragent
  2. 通过cmd安装python3.9 怎么在cmd中下载安装python的库_python_03


  3. 通过cmd安装python3.9 怎么在cmd中下载安装python的库_windows_04

  4. 卸载
    pip uninstall fake_useragent
  5. 通过cmd安装python3.9 怎么在cmd中下载安装python的库_python_05