Python的包管理器

描述

包管理器负责包的安装、更新以及自动安装包的依赖。

Python作为主流的编程语言,在管理系统、大数据、人工智能等方面应用广泛,同时,Python的版本也较多,相应的标准库和第三方库也非常多。

为更好地管理这些版本和库,Python的包管理器有pip、conda、pipenv、poetry等。

软件包中的软件包数量庞大,版本多样,需要使用pip、conda、pipenv、poetry等软件源管理工具。

1. pip

pip是Python包的通用管理器,全称为package installer for python,用来安装、更新、卸载python的第三方库。

pip的下载源为PyPi(Python Package Index,https://pypi.org/),当执行pip命令时,就会从https://pypi.org/下载库,然后安装到Python中($(python安装目录)\\lib\\site-packages)。

Ubuntu 18.04 默认安装Python2和Python3,但未安装pip和pip3。

root@linux:~# python --version
Python 3.6.9
root@linux:~# python3 --version
Python 3.6.9
root@linux:~# pip3 --version
Command 'pip3' not found, but can be installed with:
apt install python3-pip
root@linux:~# pip --version
Command 'pip' not found, but can be installed with:
apt install python-pip

执行命令分别安装pip和pip3。

apt install python-pip
apt install python3-pip

安装后,可查看具体版本信息

root@linux:~# pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

pip安装成功后,便可以执行pip install 来安装软件包。

2. Conda

Pip是Python包管理器,Conda是软件包管理器,适用于任何语言。

Conda在Anaconda/Miniconda已经打包好,后者提供Python + Conda + 软件包,其中,Anaconda意为“蟒蛇”,提供了非常多的软件包,用于科学计算、数据分析。

Anaconda源为https://www.anaconda.com/,也可以使用清华源https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/。

Miniconda源为https://docs.conda.io/en/latest/miniconda.html

Anaconda的安装,下载链接:

https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/

......
Anaconda3-2021.05-Linux-aarch64.sh412.6 MiB2021-05-14 11:33
Anaconda3-2021.05-MacOSX-x86_64.pkg440.3 MiB2021-05-14 11:33
Anaconda3-2021.05-Linux-x86_64.sh544.4 MiB2021-05-14 11:33
Anaconda3-2021.05-Linux-s390x.sh291.7 MiB2021-05-14 11:33
Anaconda3-2021.05-MacOSX-x86_64.sh432.7 MiB2021-05-14 11:34
Anaconda3-2021.05-Windows-x86.exe408.5 MiB2021-05-14 11:34
Anaconda3-2021.05-Windows-x86_64.exe477.2 MiB2021-05-14 11:34
Anaconda3-2021.11-Linux-aarch64.sh487.7 MiB2021-11-18 02:14
Anaconda3-2021.11-Linux-ppc64le.sh254.9 MiB2021-11-18 02:14
Anaconda3-2021.11-Linux-s390x.sh241.7 MiB2021-11-18 02:14
Anaconda3-2021.11-Linux-x86_64.sh580.5 MiB2021-11-18 02:14
Anaconda3-2021.11-MacOSX-x86_64.pkg515.1 MiB2021-11-18 02:14
Anaconda3-2021.11-MacOSX-x86_64.sh508.4 MiB2021-11-18 02:14
Anaconda3-2021.11-Windows-x86.exe404.1 MiB2021-11-18 02:14
Anaconda3-2021.11-Windows-x86_64.exe510.3 MiB2021-11-18 02:14

选择Anaconda3-2021.05-Linux-x86_64.sh。下载完成后,进行安装。

root@linux:/home# ls
Anaconda3-2021.05-Linux-x86_64.sh  ftp  linux
root@linux:/home# Anaconda3-2021.05-Linux-x86_64.sh
Anaconda3-2021.05-Linux-x86_64.sh: command not found
root@linux:/home# bash Anaconda3-2021.05-Linux-x86_64.sh
Welcome to Anaconda3 2021.05
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>> 
===================================
End User License Agreement - Anaconda Individual Edition
===================================
Copyright 2015-2021, Anaconda, Inc.
All rights reserved under the 3-clause BSD License:
......
Do you accept the license terms? [yes|no]
Please answer 'yes' or 'no':'
>>> yes
Anaconda3 will now be installed into this location:
/root/anaconda3
  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation  
  - Or specify a different location below


[/root/anaconda3] >>> 
Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes
......
conda config --set auto_activate_base false
Thank you for installing Anaconda3!
===========================================================================
Working with Python and Jupyter notebooks is a breeze with PyCharm Pro,
designed to be used with Anaconda. Download now and have the best data
tools at your fingertips.
PyCharm Pro for Anaconda is available at: https://www.anaconda.com/pycharm
(base) root@linux:/home# python
Python 3.8.8 (default, Apr 13 2021, 19:58:26) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
 (base) root@linux:/home# conda --version
conda 4.10.1
(base) root@linux:/home# conda env list
# conda environments:
#
base                  *  /root/anaconda3
打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分