Python基础必掌握的pip管理依赖项

Python 的标准包管理器是 pip。允许安装和管理不属于 Python 标准库的包。

整套学习自学教程中应用的数据都是《三國志》、《真·三國無雙》系列游戏中的内容。

Python基础必掌握的pip管理依赖项

开始使用pip

pip是一个安装和管理不作为标准库的一部分分发的库和依赖项的工具。

系统上查找pip

windows系统下。

C:\Users\Lenovo>where pip3
d:\MyTools\Anaconda3_5.2.0\Scripts\pip3.exe

Linux + maxOS系统下。

[root@VM_0_15_centos ~]# which pip3
/usr/bin/pip3

虚拟环境中使用pip

C:\> python -m venv venv
C:\> venv\Scripts\activate.bat
(venv) C:\>  pip3 --version
pip 21.2.3 from ...\lib\site-packages\pip (python 3.10)
(venv) C:\>  pip --version
pip 21.2.3 from ...\lib\site-packages\pip (python 3.10)

需要重装pip的情况

  • widows 'pip' is not recognized as an internal or external command, operable program or batch file.
  • Linux bash: pip: command not found
  • macOS zsh: command not found: pip

安装pip软件包

直接安装 python 的时候安装 Anaconda 版本全部自动化安装,这里都以 windows 环境举例。

pip 安装 python 第三方包

pip install pandas

pip 安装 指定版本的 python 第三方包

pip install pandas==xx.xx.xx

pip 升级 python 第三方包

pip install --upgrade pandas

pip 卸载 python 第三方包

pip uninstall pandas

Python 包索引 (PyPI)

显示已经安装的三方包名称和版本。

python -m pip list


Python基础必掌握的pip管理依赖项


使用镜像加速

清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣:http://pypi.douban.com/simple/

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas

永久更换镜像源。

新建pip目录 路径 C:\Users\xx\pip
新建文件pip.ini

[global] 
timeout = 1000 
index-url = https://pypi.tuna.tsinghua.edu.cn/simple # 你要更换的
trusted-host = pypi.tuna.tsinghua.edu.cn

pip 按照 requirements 目录安装

# 导出命令
pip freeze > requirements.txt

# 安装命令
pip install -r requirements.txt


Python基础必掌握的pip管理依赖项

基础   Python   pip
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章