开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第14天
本文首发于CSDN。
最近更新:2022.10.10 最初更新:2021.12.8
- pip简介:一种用于管理Python包的工具。
- pip文档:User Guide - pip documentation v22.1.1
- 在virtualenv或conda create的虚拟环境下直接使用pip,就可以将包安装在指定环境下。如果不在Python环境下,需要在命令行前面加上
python -m(如果Python解释器不在默认路径,就用完整的解释器路径,举例:/home/myusername/anaconda3/envs/envname/bin/python -m) pip install- 直接安装包,示例代码:
pip install numpy(一般建议参考包官网及pypi官网,了解具体的包安装方式) - 可以直接通过这一方式安装最新版本的常用包(不便直接使用pip install的包一般都在其官网有写具体的安装方式,部分包我撰写过相应的安装指南)
- numpy:
pip install numpy - scipy:
pip install scipy官网安装教程:SciPy - Installation - scikit-learn (sklearn):
pip install scikit-learn官网下载教程:Installing scikit-learn — scikit-learn 1.1.1 documentation - matplotlib:
pip install matplotlib官网入门教程:Getting started — Matplotlib 3.5.3 documentation - wordcloud:
pip install wordcloudpypi网站:wordcloud · PyPI(虽然网页上只说测试到了Python3.7,其实Python3.8也能用),文档:WordCloud for Python documentation — wordcloud 1.8.1 documentation,官方博文:A Wordcloud in Python,GitHub项目:amueller/word_cloud: A little word cloud generator in Python - gensim:
pip install gensim官网:Gensim: Topic modelling for humans - pyLDAvis:
pip install pyldavis官方文档:pyLDAvis — pyLDAvis 2.1.2 documentation - tqdm:
pip install tqdm官方GitHub项目:tqdm/tqdm: A Fast, Extensible Progress Bar for Python and CLI - seaborn:
pip install seaborn官网下载教程:Installing and getting started — seaborn 0.11.2 documentation - sentence_transformers:
pip install sentence_transformers官网:sentence-transformers (Sentence Transformers) - pybind11:
pip install pybind11官网下载教程:Installing the library — pybind11 documentation
- numpy:
- 指定安装某一版本的包,示例代码:
pip install numpy==1.14 - 如果出现网络问题等,无法直接通过包名下载,也可以将指定包的whl文件下载后,通过pip直接安装whl文件,示例代码:
pip install torch_scatter-2.0.9-cp39-cp39-linux_x86_64.whl - 参数
--upgrade或-U更新包到最新版本,示例代码:pip install --upgrade numpy(文档地址:pip.pypa.io/en/stable/c…)- 参数
--pre下载pre-release或development版本。(默认情况下pip会搜索stable版本的包) 示例代码:pip install --pre dgl-cu102 -f https://data.dgl.ai/wheels-test/repo.html - 参数
-i指定源,示例代码:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple cogdl(清华源使用方法可参考:pypi | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror) - 参数
-e, --editable <path/url>以editable mode,从本地项目路径或一个VCS URL安装包。示例代码:pip install -e . - 参数
--user安装到Python用户的install directory里,一般来说是~/.local/,Windows平台一般是%APPDATA%Python,可以查看Python文档里的site.USER_BASE(对应网址:site — Site-specific configuration hook — Python 3.10.4 documentation)来了解详情。(文档地址:pip.pypa.io/en/stable/c…) - 参数
-i, --index-url <url>Python包搜索位置。默认值:pypi.org/simple - 参数
--extra-index-url <url>--index-url的补充超链接 - 参数
-f-可以指定在某网页中搜索下载指定版本的包(一般都是包官方给出的安装方式),示例代码:pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cu102.html
- 直接安装包,示例代码:
pip show展示包的信息,示例代码:pip show numpy打印信息:
Name: numpy
Version: 1.21.2
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email:
License: BSD
Location: /home/myusername/anaconda3/envs/envname/lib/python3.8/site-packages
Requires:
Required-by: transformers, torchvision, torch, scipy, pandas, mkl-random, mkl-fft, matplotlib
pip list打印已安装的包的简略信息 打印的示例(部分):
Package Version
----------------------------- ----------
anyio 3.4.0
argon2-cffi 20.1.0
async-generator 1.10
attrs 21.2.0
Babel 2.9.1
backcall 0.2.0
backports.functools-lru-cache 1.6.4
pip cache dir打印pip的cache文件夹which pip打印pip的路径