如何使用 pip 查看电脑上是否安装了哪个 python 包?

最近用起了 Anaconda,里面预装了连绵不绝的一堆常用的三方包,用起来可爽啦!

不过也遇到了一个烦恼的问题,因为它预装太多三方包了,每次用 pip list 查看包的时候,总给我显示一堆堆的包列表出来,想在里面找一下是否已经预装了某个包,装的版本是多少,别提有多麻烦了。

于是我们就来学习下如何查看自己电脑有没有安装某个包呢?

pip show 包名
pip show --files 包名

用上面的代码即可!一般用第一条,如果已安装会返回包的信息,如果未安装则会返回找不到。如果需要在看信息的基础上,还需要看看包中包含了哪些个文件,可以用第二条命令来搜索。下面是我在本机测试的一些返回信息:

C:\Users\HP>pip show beautifulsoup4
Name: beautifulsoup4
Version: 4.9.3
Summary: Screen-scraping library
Home-page: http://www.crummy.com/software/BeautifulSoup/bs4/
Author: Leonard Richardson
Author-email: leonardr@segfault.org
License: MIT
Location: e:\programfiles\anaconda\lib\site-packages
Requires: soupsieve
Required-by: conda-build

C:\Users\HP>pip show bs4
WARNING: Package(s) not found: bs4

C:\Users\HP>pip show jupyterlab
Name: jupyterlab
Version: 3.0.4
Summary: The JupyterLab server extension.
Home-page: http://jupyter.org
Author: Jupyter Development Team
Author-email: jupyter@googlegroups.com
License: BSD
Location: e:\programfiles\anaconda\lib\site-packages
Requires: jupyter-server, jupyterlab-server, jupyter-core, nbclassic, jinja2, packaging, ipython, tornado
Required-by: jupyterlab-lsp

C:\Users\HP>pip show requests
Name: requests
Version: 2.24.0
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: e:\programfiles\anaconda\lib\site-packages
Requires: idna, certifi, urllib3, chardet
Required-by: Sphinx, nbdime, jupyterlab-server, conda, conda-build, anaconda-project, anaconda-client

C:\Users\HP>pip show --files beautifulsoup4
Name: beautifulsoup4
Version: 4.9.3
Summary: Screen-scraping library
Home-page: http://www.crummy.com/software/BeautifulSoup/bs4/
Author: Leonard Richardson
Author-email: leonardr@segfault.org
License: MIT
Location: e:\programfiles\anaconda\lib\site-packages
Requires: soupsieve
Required-by: conda-build
Files:
  beautifulsoup4-4.9.3.dist-info\COPYING.txt
  beautifulsoup4-4.9.3.dist-info\INSTALLER
  beautifulsoup4-4.9.3.dist-info\LICENSE
  beautifulsoup4-4.9.3.dist-info\METADATA
  beautifulsoup4-4.9.3.dist-info\RECORD
  beautifulsoup4-4.9.3.dist-info\REQUESTED
  beautifulsoup4-4.9.3.dist-info\WHEEL
  beautifulsoup4-4.9.3.dist-info\direct_url.json
  beautifulsoup4-4.9.3.dist-info\top_level.txt
  bs4\__init__.py
  bs4\__pycache__\__init__.cpython-38.pyc
  bs4\__pycache__\dammit.cpython-38.pyc
  bs4\__pycache__\diagnose.cpython-38.pyc
  bs4\__pycache__\element.cpython-38.pyc
  bs4\__pycache__\formatter.cpython-38.pyc
  bs4\__pycache__\testing.cpython-38.pyc
  bs4\builder\__init__.py
  bs4\builder\__pycache__\__init__.cpython-38.pyc
  bs4\builder\__pycache__\_html5lib.cpython-38.pyc
  bs4\builder\__pycache__\_htmlparser.cpython-38.pyc
  bs4\builder\__pycache__\_lxml.cpython-38.pyc
  bs4\builder\_html5lib.py
  bs4\builder\_htmlparser.py
  bs4\builder\_lxml.py
  bs4\dammit.py
  bs4\diagnose.py
  bs4\element.py
  bs4\formatter.py
  bs4\testing.py
  bs4\tests\__init__.py
  bs4\tests\__pycache__\__init__.cpython-38.pyc
  bs4\tests\__pycache__\test_builder_registry.cpython-38.pyc
  bs4\tests\__pycache__\test_docs.cpython-38.pyc
  bs4\tests\__pycache__\test_html5lib.cpython-38.pyc
  bs4\tests\__pycache__\test_htmlparser.cpython-38.pyc
  bs4\tests\__pycache__\test_lxml.cpython-38.pyc
  bs4\tests\__pycache__\test_soup.cpython-38.pyc
  bs4\tests\__pycache__\test_tree.cpython-38.pyc
  bs4\tests\test_builder_registry.py
  bs4\tests\test_docs.py
  bs4\tests\test_html5lib.py
  bs4\tests\test_htmlparser.py
  bs4\tests\test_lxml.py
  bs4\tests\test_soup.py
  bs4\tests\test_tree.py

学会了吗?是不是很简单呢?快用起来吧!

评论区
头像