Cómo instalar Pip en CentOS 8
En este tutorial, instalaremos Python pip en CentOS 8 usando el administrador de paquetes yum y cubriremos los conceptos básicos de cómo instalar y administrar paquetes de Python con pip. En el repositorio de CentOS 8 AppStream, hay versiones de pip para Python 2 y también para el intérprete de Python 3. El comando pip ahora se ejecuta con el comando pip2 o pip3 respectivamente.
¿Qué es PIP?
pip es el administrador de paquetes (módulos) estándar para Python. Le permite instalar y administrar paquetes adicionales que no forman parte de la biblioteca estándar de Python. Los módulos son bibliotecas de código de Python que puede incluir y usar en sus proyectos. pip se ha incluido con el instalador de Python desde las versiones 3.4 para Python 3 y 2.7.9 para Python 2, y muchos proyectos de Python lo utilizan, lo que lo convierte en una herramienta esencial para todos los programadores de Python.
Instalación de pip
En CentOS 8 puede instalar paquetes con el comando dnf o yum. Podemos instalar el paquete pip2 o pip3 dependiendo de la versión de Python que usemos, o también podríamos instalar ambos paquetes, sin ningún problema.
Instalación de python2-pip
Primero, actualizamos el sistema:
$ sudo yum update
Instalaremos los paquetes python2-pip y python3-pip.
Primero, instalamos python2-pip:
$ sudo yum -y install python2-pip Last metadata expiration check: 2:12:46 ago on Tue 01 Oct 2019 01:19:15 PM UTC. Dependencies resolved. =============================================================================== Package Arch Version Repository Size =============================================================================== Installing: python2-pip noarch 9.0.3-13.module_el8.0.0+32+017b2cba AppStream 2.0 M Installing dependencies: python2 x86_64 2.7.15-22.module_el8.0.0+32+017b2cba AppStream 107 k python2-libs x86_64 2.7.15-22.module_el8.0.0+32+017b2cba AppStream 6.0 M python2-setuptools noarch 39.0.1-11.module_el8.0.0+32+017b2cba AppStream 643 k Enabling module streams: python27 2.7 Transaction Summary =============================================================================== Install 4 Packages Total download size: 8.7 M Installed size: 36 M Downloading Packages: (1/4): python2-2.7.15-22.module_el8.0.0+32+017 70 kB/s | 107 kB 00:01 (2/4): python2-setuptools-39.0.1-11.module_el8 689 kB/s | 643 kB 00:00 (3/4): python2-pip-9.0.3-13.module_el8.0.0+32+ 777 kB/s | 2.0 MB 00:02 (4/4): python2-libs-2.7.15-22.module_el8.0.0+3 1.4 MB/s | 6.0 MB 00:04 ------------------------------------------------------------------------------- Total 2.0 MB/s | 8.7 MB 00:04 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : python2-libs-2.7.15-22.module_el8.0.0+32+017b2cba.x 1/4 Installing : python2-pip-9.0.3-13.module_el8.0.0+32+017b2cba.noa 2/4 Installing : python2-setuptools-39.0.1-11.module_el8.0.0+32+017b 3/4 Installing : python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64 4/4 Running scriptlet: python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64 4/4 Verifying : python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64 1/4 Verifying : python2-libs-2.7.15-22.module_el8.0.0+32+017b2cba.x 2/4 Verifying : python2-pip-9.0.3-13.module_el8.0.0+32+017b2cba.noa 3/4 Verifying : python2-setuptools-39.0.1-11.module_el8.0.0+32+017b 4/4 Installed: python2-pip-9.0.3-13.module_el8.0.0+32+017b2cba.noarch python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64 python2-libs-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64 python2-setuptools-39.0.1-11.module_el8.0.0+32+017b2cba.noarch Complete!
Instalación de python3-pip
Instalamos el paquete python3-pip de la misma manera:
$ sudo yum -y install python3-pip CentOS-8 - AppStream 3.3 kB/s | 4.3 kB 00:01 CentOS-8 - Base 1.7 kB/s | 3.8 kB 00:02 CentOS-8 - Extras 1.4 kB/s | 1.5 kB 00:01 Docker CE Stable - x86_64 3.1 kB/s | 3.5 kB 00:01 Extra Packages for Enterprise Linux 8 - x86_64 17 kB/s | 32 kB 00:01 Extra Packages for Enterprise Linux 8 - x86_64 464 kB/s | 1.8 MB 00:04 Dependencies resolved. =============================================================================== Package Arch Version Repository Size =============================================================================== Installing: python3-pip noarch 9.0.3-13.el8 AppStream 18 k Installing dependencies: python36 x86_64 3.6.8-2.module_el8.0.0+33+0a10c0e1 AppStream 19 k python3-setuptools noarch 39.2.0-4.el8 BaseOS 162 k Enabling module streams: python36 3.6 Transaction Summary =============================================================================== Install 3 Packages Total download size: 200 k Installed size: 466 k Downloading Packages: (1/3): python3-pip-9.0.3-13.el8.noarch.rpm 15 kB/s | 18 kB 00:01 (2/3): python36-3.6.8-2.module_el8.0.0+33+0a10 14 kB/s | 19 kB 00:01 (3/3): python3-setuptools-39.2.0-4.el8.noarch. 97 kB/s | 162 kB 00:01 ------------------------------------------------------------------------------- Total 70 kB/s | 200 kB 00:02 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : python3-setuptools-39.2.0-4.el8.noarch 1/3 Installing : python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64 2/3 Running scriptlet: python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64 2/3 Installing : python3-pip-9.0.3-13.el8.noarch 3/3 Running scriptlet: python3-pip-9.0.3-13.el8.noarch 3/3 Verifying : python3-pip-9.0.3-13.el8.noarch 1/3 Verifying : python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64 2/3 Verifying : python3-setuptools-39.2.0-4.el8.noarch 3/3 Installed: python3-pip-9.0.3-13.el8.noarch python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64 python3-setuptools-39.2.0-4.el8.noarch Complete!
A continuación, deberíamos verificar que la instalación del paquete fue bien.
Confirmar la instalación consultando el número de versión
Consultaremos la información de la versión en python2-pip y python3-pip con los siguientes comandos:
$ pip2 -V pip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)
Para python3-pip escribimos:
$ pip3 -V pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
Buscando paquetes de Python
Digamos que queremos instalar algún módulo con pip pero no sabemos el nombre exacto del módulo. Podemos buscar los paquetes disponibles usando una palabra clave.
$ pip2 search docker
o
$ pip3 search docker docker (4.0.2) - A Python library for the Docker Engine API. docker-utils (0.1.4) - Utilities for Docker Fifty-Docker (1.1) - Docker utilities. monit-docker (0.0.32) - monit-docker docker-deployer (0.1.0) - A Fabric framework for Docker deployment based on Docker-Compose. docker-pid (0.0.3) - docker-pid: Listing process IDs in docker containers. docker-fabric (0.5.0) - Build Docker images, and run Docker containers in Fabric. morgaroth-docker (0.0.1) - Morgaroths Docker Client docker-api (0.1.3) - Docker API Client docker-wrapper (2.1.2) - Docker Wrapper for Python docker-registry (0.9.1) - Registry server for Docker docker-py (1.10.6) - Python client for Docker. docker-cloud (1.0.9) - CLI for Docker Cloud docker-dev (1.0b2) - Development tools for Docker pysecrets-docker (1.0.0) - Docker secrets to ENV docker-master (0.0.2) - An alternative to docker-compose bonobo-docker (0.6.0) - Docker extension for Bonobo colomoto-docker (7.2) - Helper script to run docker image colomoto/colomoto-docker docker-parse (0.5.6) - Parse docker-run options from a running Docker container .....
La lista continúa, pero elegiremos instalar el módulo docker-fabric en el siguiente ejemplo.
Instalación de módulos (paquetes) usando PIP
Podemos instalar el paquete docker-fiber usando un simple comando pip:
$ pip3 install docker-fabric Collecting docker-fabric Downloading https://files.pythonhosted.org/packages/1d/66/2c75e141373dca58ec20ccdbb2b2204a07e02f692c7fc42c83fe98e71bfd/docker-fabric-0.5.0.tar.gz Requirement already satisfied: six in /usr/lib/python3.6/site-packages (from docker-fabric) Collecting Fabric>=1.8.0 (from docker-fabric) Downloading https://files.pythonhosted.org/packages/d7/cb/47feeb00dae857f0fbd1153a61e902e54ed77ccdc578b371a514a3959a19/fabric-2.5.0-py2.py3-none-any.whl (51kB) 100% |████████████████████████████████| 61kB 1.3MB/s Collecting docker-py>=1.9.0 (from docker-fabric) Downloading https://files.pythonhosted.org/packages/23/c7/1fd6d4d620809fe2f323869d719e2dd0086c939b67021303a9ec40f5a05b/docker_py-1.10.6-py2.py3-none-any.whl (50kB) 100% |████████████████████████████████| 51kB 4.8MB/s Collecting docker-map>=0.8.0b2 (from docker-fabric) Downloading https://files.pythonhosted.org/packages/c8/31/b23be95ca29113b0af3fc3c931de5f471f3a7e07af0d4ce29d47445dcc07/docker-map-1.0.0.tar.gz (109kB) 100% |████████████████████████████████| 112kB 2.5MB/s Collecting paramiko>=2.4 (from Fabric>=1.8.0->docker-fabric) Downloading https://files.pythonhosted.org/packages/4b/80/74dace9e48b0ef923633dfb5e48798f58a168e4734bca8ecfaf839ba051a/paramiko-2.6.0-py2.py3-none-any.whl (199kB) .... Running setup.py install for docker-map ... done Running setup.py install for docker-fabric ... done Successfully installed Fabric-2.5.0 bcrypt-3.1.7 certifi-2019.9.11 chardet-3.0.4 cryptography-2.7 docker-fabric-0.5.0 docker-map-1.0.0 docker-py-1.10.6 docker-pycreds-0.4.0 invoke-1.3.0 paramiko-2.6.0 pynacl-1.3.0 requests-2.22.0 urllib3-1.25.6 websocket-client-0.56.0
Lista de paquetes instalados
Para listar los paquetes instalados usamos este comando:
$ pip3 list bcrypt (3.1.7) certifi (2019.9.11) cffi (1.11.5) chardet (3.0.4) configobj (5.0.6) cryptography (2.7) decorator (4.2.1) docker-fabric (0.5.0) docker-map (1.0.0) docker-py (1.10.6) docker-pycreds (0.4.0) fabric (2.5.0) gpg (1.10.0) idna (2.5) .....
Para enumerar los paquetes desactualizados, escribimos:
$ pip2 list --outdated pip (9.0.3) - Latest: 19.2.3 [wheel] setuptools (39.0.1) - Latest: 41.2.0 [wheel]
Eliminando módulos (paquetes) usando PIP
Lo único que queda por ver en este tutorial es cómo eliminar el paquete pip. Es bastante simple, escribimos:
$ pip3 uninstall docker-fabric Uninstalling docker-fabric-0.5.0: /usr/local/lib/python3.6/site-packages/docker_fabric-0.5.0-py3.6.egg-info /usr/local/lib/python3.6/site-packages/dockerfabric/__init__.py /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/__init__.cpython-36.pyc /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/actions.cpython-36.pyc /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/api.cpython-36.pyc /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/apiclient.cpython-36.pyc ..... /usr/local/lib/python3.6/site-packages/dockerfabric/utils/output.py /usr/local/lib/python3.6/site-packages/dockerfabric/utils/users.py /usr/local/lib/python3.6/site-packages/dockerfabric/yaml.py Proceed (y/n)? y
Se le presentará la lista de archivos a punto de eliminarse. Cuando procedamos escribiendo y, el paquete será eliminado.
Proceed (y/n)? y Successfully uninstalled docker-fabric-0.5.0
Conclusión
Ha instalado con éxito pip en su sistema CentOS 8 y ha aprendido a instalar y desinstalar fácilmente módulos de Python con pip. Para obtener más información, puede consultar la guía del usuario de pip. Si tiene alguna pregunta o comentario, no dude en comentar a continuación.
Leer también: