
Este es uno de esos casos en lo que una cosa lleva a otra y a otra y a otra… Inicié con el API de Twitter, que me llevó a Tweepy, y de ahí a git
junto con pip
. Por el momento una simple recolección de notas.
Índice
Panorama
Personalmente, siempre vi a Python como algo mucho más sencillo que Java. No sólo en lo que al lenguaje de programación se refiere sino también en la tecnología detrás de éste. Sin embargo, no es difícil que, sumado a lo que se ha construido, uno puede meter el suficiente desorden para complicar bastante las cosas casi en la misma medida que Java.
Mucho del desorden, complicaciones, extraños errores o comportamiento errático tienen como causas raíz la forma descuidad en que módulos, extensiones y agregados son adicionados en el entorno de trabajo. Así que, esta página tiene el propósito de compartir un poco la experiencia de limpieza y organización sobre el entorno de trabajo.
Caso
Mucho de lo que aquí se describe, se gestó en una MacBook cuyo sistema operativo ha pasado por OS X 10.9, macOS 10.12, 10.13, 10.14, y 10.15 y sobre la que se han instalado diferentes versiones de Python con pip
, MacPorts, Brew, y mediante los instaladores de algunas distribuciones descargadas de python.org (versiones 3.x) y de terceros (como Anaconda de Continuum Analytics con Python 2.7.15 y Python 3.x). Sobre los que se trabajó descargando paquetes según se necesitaban. En menor medida están las anotaciones sobre entornos con Windows y Linux.
Consistencia
Un punto importante en el uso de pip
(o de cualquier otro administrador de paquetes) es el hacer uso de éste siempre, es decir, ya sea que se cuente con otro administrador de paquetes, y se tenga o no entornos virtualizados (por ejemplo con virtualenv
o con conda
), se debe hacer siempre uso del mismo administrador de paquetes. No es nada recomendable mezclar su instalación alternando entre los distintos administradores con que se cuente.
Python 2.7
Por razones históricas se ha dejado al inicio lo referente a Python 2.7, que fue con lo que se inició estas notas.
Instalación
pip
es un administrador de paquetes de Python que facilita mucho la administración de módulos que diversos productos, utilerías y proyectos desarrollados en este lenguaje. Su instalación es simple mediante easy_install
, que es incluido con la distribución de Python y a partir de éste es posible instalar pip
. Lo siguiente es un ejemplo al respecto.
$ sudo easy_install pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Best match: pip 6.0.6
Downloading https://pypi.python.org/packages/source/p/pip/pip-6.0.6.tar.gz#md5=bbb17814bdf82187f46aaf9cec6b6caa
Processing pip-6.0.6.tar.gz
Running pip-6.0.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-IesvBa/pip-6.0.6/egg-dist-tmp-8rrrMn
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
Adding pip 6.0.6 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/pip-6.0.6-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
$
Versiones instaladas de pip
Revisar las versiones instaladas de pip
es simple y hay varias formas de hacerlo. La más simple y directa es revisar cuál es el pip
con el que uno está trabajando.$ pip -V
pip 18.1 from /Library/Python/2.7/site-packages/pip (python 2.7)
$ type pip
pip is hashed (/usr/local/bin/pip)
$ python -m pip show -f pip
Actualización
Python 2.7 está ya congelado en su desarrollo, aunque cuenta aún con soporte al momento en que se escribieron estas notas, pero su tiempo ya está contado. Algo similar ocurre con su librerías.
WARNING: You are using pip version 19.3.1; however, version 20.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Limpieza
Conforme al caso que se describe al inicio de esta página, nos encontramos con un equipo en el que se han instalado distintas versiones de Python adicionales al que Apple provee con el sistema operativo. La distribución de Python proporcionada por Apple se encuentra instalada en /System/Library/Frameworks/Python.framework
y /usr/bin
. Esta nunca debe modificarse o eliminarse, ya que está controlada y es utilizada tanto por Apple o terceros para cuestiones de administración de software. Si elige instalar una versión más reciente de Python, se tendrán dos instalaciones de Python diferentes pero funcionales y es importante que sus rutas y usos sean coherentes con lo que se pretende hacer. Claro que al final esto es sólo un buen deseo. En la práctica hay muchas causas por las que uno puede olvidarlo o deliberadamente obviarlo. Cuando esto pasa no es raro que errores de privilegios, accesos o comportamiento errático de programas y desarrollo se presente. Momento en el que conviene hacer algo de limpieza. Dicha limpieza puede consistir en desinstalar los paquete agregados y volverlos a instalar. Puede incluso ser necesario desinstalar a pip
mismo.
Desinstalación
Idealmente la desinstalación de pip, debería limitarse a
sudo pip uninstall pip
Adicionalmente , puede ser que se requiera la desinstalación de setuptools
:
python -m pip uninstall pip setuptools
Antes de proceder con la eliminación de pip y algún otro paquete, además de leer la declaración de responsabilidad del sitio, conviene evaluar las acciones a realizar y proceder con éstos antes que con pip
y setuptools
, que puede hacerse con:
pip freeze | grep -v "^-e" | grep -v "^(setuptools|pip)" | xargs pip uninstall -y
Python 3.x
Posibles problemas y su solución
Estos son algunos problemas que pueden presentarse al hacer uso de pip
:
Sin conexión a internet o conexión atascada
Si uno está detrás de un proxy, conviene revisar o refrescar el acceso a éste (entiéndase «la salida a internet»). Usualmente errores de time out, pueden deberse a esto.
$ sudo easy_install pip
Password:
Searching for pip
Reading http://pypi.python.org/simple/pip/
Download error: [Errno 60] Operation timed out -- Some packages may not be found!
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
Download error: [Errno 60] Operation timed out -- Some packages may not be found!
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')
$
** Lo siguiente es aun material a ser arreglado y formateado **
The scripts pyrsa-decrypt, pyrsa-decrypt-bigfile, pyrsa-encrypt, pyrsa-encrypt-bigfile, pyrsa-keygen, pyrsa-priv2pub, pyrsa-sign and pyrsa-verify are installed in ‘/Users/lalo/Library/Python/2.7/bin’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use –no-warn-script-location.
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: ‘/usr/local/bin/virtualenv’
Consider using the `–user` option or check the permissions.
$ pip list
Package Version
————————————– ———
absl-py 0.6.1
altgraph 0.10.2
astor 0.7.1
…
wheel 0.32.3
xattr 0.6.4
zope.interface 4.1.1
$ pip uninstall tweepy tensorboard tensorflow scipy scikit-learn
Uninstalling tensorflow-1.12.0:
Would remove:
/Library/Python/2.7/site-packages/tensorflow-1.12.0.dist-info/*
/Library/Python/2.7/site-packages/tensorflow/*
/usr/local/bin/freeze_graph
/usr/local/bin/saved_model_cli
/usr/local/bin/tensorboard
/usr/local/bin/tflite_convert
/usr/local/bin/toco
/usr/local/bin/toco_from_protos
Proceed (y/n)? y
Exception:
Traceback (most recent call last):
File «/Library/Python/2.7/site-packages/pip/_internal/cli/base_command.py», line 143, in main
status = self.run(options, args)
File «/Library/Python/2.7/site-packages/pip/_internal/commands/uninstall.py», line 75, in run
auto_confirm=options.yes, verbose=self.verbosity > 0,
File «/Library/Python/2.7/site-packages/pip/_internal/req/req_install.py», line 683, in uninstall
uninstalled_pathset.remove(auto_confirm, verbose)
File «/Library/Python/2.7/site-packages/pip/_internal/req/req_uninstall.py», line 224, in remove
renames(path, new_path)
File «/Library/Python/2.7/site-packages/pip/_internal/utils/misc.py», line 280, in renames
shutil.move(old, new)
File «/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py», line 303, in move
os.unlink(src)
OSError: [Errno 13] Permission denied: ‘/Library/Python/2.7/site-packages/tensorflow-1.12.0.dist-info/DESCRIPTION.rst’
$ sudo pip uninstall tweepy tensorboard tensorflow scipy scikit-learn
Password:
Sorry, try again.
Password:
Sorry, try again.
Password:
The directory ‘/Users/lalo/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Uninstalling tensorflow-1.12.0:
Would remove:
/Library/Python/2.7/site-packages/tensorflow-1.12.0.dist-info/*
/Library/Python/2.7/site-packages/tensorflow/*
/usr/local/bin/freeze_graph
/usr/local/bin/saved_model_cli
/usr/local/bin/tensorboard
/usr/local/bin/tflite_convert
/usr/local/bin/toco
/usr/local/bin/toco_from_protos
Proceed (y/n)? y
Successfully uninstalled tensorflow-1.12.0
Uninstalling scipy-1.1.0:
Would remove:
/Library/Python/2.7/site-packages/scipy-1.1.0.dist-info/*
/Library/Python/2.7/site-packages/scipy/*
Proceed (y/n)? y
Successfully uninstalled scipy-1.1.0
Uninstalling scikit-learn-0.20.1:
Would remove:
/Library/Python/2.7/site-packages/scikit_learn-0.20.1.dist-info/*
/Library/Python/2.7/site-packages/sklearn/*
Proceed (y/n)? y
Successfully uninstalled scikit-learn-0.20.1
Uninstalling tensorboard-1.12.0:
Would remove:
/Library/Python/2.7/site-packages/tensorboard-1.12.0.dist-info/*
/Library/Python/2.7/site-packages/tensorboard/*
Proceed (y/n)? y
Successfully uninstalled tensorboard-1.12.0
Uninstalling tweepy-3.3.0:
Would remove:
/Library/Python/2.7/site-packages/examples/*
/Library/Python/2.7/site-packages/tweepy-3.3.0.dist-info/*
/Library/Python/2.7/site-packages/tweepy/*
Proceed (y/n)? y
Successfully uninstalled tweepy-3.3.0
$ sudo pip uninstall pandas matplotlib numpy
The directory ‘/Users/lalo/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Uninstalling numpy-1.15.4:
Would remove:
/Library/Python/2.7/site-packages/numpy-1.15.4.dist-info/*
/Library/Python/2.7/site-packages/numpy/*
/usr/local/bin/f2py
Proceed (y/n)? y
Successfully uninstalled numpy-1.15.4
Uninstalling pandas-0.23.4:
Would remove:
/Users/lalo/Library/Python/2.7/lib/python/site-packages/pandas-0.23.4.dist-info/*
/Users/lalo/Library/Python/2.7/lib/python/site-packages/pandas/*
Proceed (y/n)? y
Successfully uninstalled pandas-0.23.4
Uninstalling matplotlib-1.3.1:
Would remove:
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib-1.3.1-py2.7.egg-info
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pylab.py
Proceed (y/n)? y
Exception:
Traceback (most recent call last):
File «/Library/Python/2.7/site-packages/pip/_internal/cli/base_command.py», line 143, in main
status = self.run(options, args)
File «/Library/Python/2.7/site-packages/pip/_internal/commands/uninstall.py», line 75, in run
auto_confirm=options.yes, verbose=self.verbosity > 0,
File «/Library/Python/2.7/site-packages/pip/_internal/req/req_install.py», line 683, in uninstall
uninstalled_pathset.remove(auto_confirm, verbose)
File «/Library/Python/2.7/site-packages/pip/_internal/req/req_uninstall.py», line 224, in remove
renames(path, new_path)
File «/Library/Python/2.7/site-packages/pip/_internal/utils/misc.py», line 280, in renames
shutil.move(old, new)
File «/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py», line 299, in move
copytree(src, real_dst, symlinks=True)
File «/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py», line 208, in copytree
raise Error, errors
Error: [(‘/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.py’, ‘/private/tmp/pip-uninstall-qMp17V/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.py’, «[Errno 1] Operation not permitted: ‘/private/tmp/pip-uninstall-qMp17V/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.py'»),…
«[Errno 1] Operation not permitted: ‘/private/tmp/pip-uninstall-qMp17V/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib'»)]
$ sudo pip uninstall numpy
The directory ‘/Users/lalo/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Cannot uninstall ‘numpy’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
$ sudo pip uninstall keras
The directory ‘/Users/lalo/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Uninstalling Keras-2.2.4:
Would remove:
/Library/Python/2.7/site-packages/Keras-2.2.4.dist-info/*
/Library/Python/2.7/site-packages/docs/*
/Library/Python/2.7/site-packages/keras/*
Proceed (y/n)? y
Successfully uninstalled Keras-2.2.4
$ pip show zope.interface
Name: zope.interface
Version: 4.1.1
Summary: Interfaces for Python
Home-page: http://pypi.python.org/pypi/zope.interface
Author: Zope Foundation and Contributors
Author-email: zope-dev@zope.org
License: ZPL 2.1
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requires: setuptools
Required-by:
$ pip show $(pip list | awk ‘NR>2{printf(«%s «, $1)}’) | more
Name: absl-py
Version: 0.6.1
Summary: Abseil Python Common Libraries, see https://github.com/abseil/abseil-py.
Home-page: https://github.com/abseil/abseil-py
Author: The Abseil Authors
Author-email: UNKNOWN
License: Apache 2.0
Location: /Library/Python/2.7/site-packages
Requires: six, enum34
Required-by:
—
Name: altgraph
Version: 0.10.2
Summary: Python graph (network) package
Home-page: http://packages.python.org/altgraph
Author: Ronald Oussoren
Author-email: ronaldoussoren@mac.com
License: MIT
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requires:
Required-by: py2app, macholib
—
…
—
Name: zope.interface
Version: 4.1.1
Summary: Interfaces for Python
Home-page: http://pypi.python.org/pypi/zope.interface
Author: Zope Foundation and Contributors
Author-email: zope-dev@zope.org
License: ZPL 2.1
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requires: setuptools
Required-by:
$ pip uninstall absl-py
Uninstalling absl-py-0.6.1:
Would remove:
/Library/Python/2.7/site-packages/absl/*
/Library/Python/2.7/site-packages/absl_py-0.6.1-py2.7.egg-info
Proceed (y/n)? y
Exception:
Traceback (most recent call last):
File «/Library/Python/2.7/site-packages/pip/_internal/cli/base_command.py», line 143, in main
status = self.run(options, args)
File «/Library/Python/2.7/site-packages/pip/_internal/commands/uninstall.py», line 75, in run
…
File «/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py», line 303, in move
os.unlink(src)
OSError: [Errno 13] Permission denied: ‘/Library/Python/2.7/site-packages/absl/__init__.py’
$ sudo pip uninstall absl-py
Password:
The directory ‘/Users/lalo/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Uninstalling absl-py-0.6.1:
Would remove:
/Library/Python/2.7/site-packages/absl/*
/Library/Python/2.7/site-packages/absl_py-0.6.1-py2.7.egg-info
Proceed (y/n)? y
Successfully uninstalled absl-py-0.6.1
Cannot uninstall ‘vboxapi’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
$ sudo pip uninstall sphynx stevedoire six
The directory ‘/Users/lalo/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Cannot uninstall ‘six’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
$ sudo pip uninstall pip
Password:
The directory ‘/Users/lalo/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Uninstalling pip-18.1:
Would remove:
/Library/Python/2.7/site-packages/pip-18.1.dist-info/*
/Library/Python/2.7/site-packages/pip/*
/usr/local/bin/pip
/usr/local/bin/pip2
/usr/local/bin/pip2.7
/usr/local/bin/pip3
/usr/local/bin/pip3.7
Proceed (y/n)? n
$ cd /Library/Python/2.7/site-packages
[…/site-packages]$ ls
Extras.pth pip-18.1.dist-info
README sphinx
Sphinx-1.2.3.dist-info tests
easy-install.pth vboxapi
pip vboxapi-1.0-py2.7.egg-info
$ cd ~/Library/Python/2.7/lib/python/site-packages
$ ls
easy-install.pth
$ pip show $(pip list | awk ‘NR>2{printf(«%s «, $1)}’) | awk ‘$1 ~ /^(Name:|Location:)/’|more
Name: altgraph
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Name: bdist-mpkg
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Name: bonjour-py
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
…
Name: xattr
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Name: zope.interface
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
$
(base) Somnium:~ evasd$ type pip
-bash: type: pip: not found
(base) Somnium:~ evasd$ type pip3
pip3 is hashed (/usr/bin/pip3)
(base) Somnium:~ evasd$ conda activate evamodels
(evamodels) Somnium:~ evasd$ type pip
pip is /Users/evasd/Applications/miniconda3/envs/evamodels/bin/pip
(evamodels) Somnium:~ evasd$ pip –version
pip 19.3.1 from /Users/evasd/Applications/miniconda3/envs/evamodels/lib/python3.6/site-packages/pip (python 3.6)
(evamodels) Somnium:~ evasd$ conda deactivate
(base) Somnium:~ evasd$ pip –version
-bash: pip: command not found
(base) Somnium:~ evasd$ pip3 –version
Traceback (most recent call last):
File «/Applications/Xcode.app/Contents/Developer/usr/bin/pip3», line 10, in <module>
sys.exit(main())
TypeError: ‘module’ object is not callable
Python 3.x
$ pip3 install –upgrade –user pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/54/2e/df11ea7e23e7e761d484ed3740285a34e38548cf2bad2bed3dd5768ec8b9/pip-20.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 19.3.1
Uninstalling pip-19.3.1:
Successfully uninstalled pip-19.3.1
WARNING: The scripts pip, pip3 and pip3.7 are installed in ‘/Users/evasd/Library/Python/3.7/bin’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use –no-warn-script-location.
Successfully installed pip-20.1
Python 3.x
$ python -m pip install --upgrade pip
Why did pip install a package into ~/.local/bin?
https://unix.stackexchange.com/questions/240037/why-did-pip-install-a-package-into-local-bin
Python Install (Conda Anaconda Miniconda Pip) on MacOS
Confusion and errors from too many alternatives and options
https://wilsonmar.github.io/python-install/
La instalación
Referencias
- «pip Documentation«, The Python Packaging Authority, web. Updated: 2018.07.08; Visited: 2018.12.17 URL: https://www.pypa.io/en/latest/.
|
© Todos los derechos reservados. Dr. Eduardo René Rodríguez Avila |
Creación: 2015.01.12 Última actualización: 2021.08.01 |
|||
El contenido de este sitio puede ser copiado y reproducido libremente mientras no sea alterado y se cite su origen. Marcas y productos registrados son citados por referencia y sin fines de lucro o dolo. Todas las opiniones son a título personal del o los autores de éstas y, salvo sea expresado de otro modo, deben considerarse como registro y expresión de la experiencia de uso de aquello que es tratado. Para conocer más sobre la posición de privacidad y responsabilidad de lo que se presenta en este sitio web y como ha sido obtenido, consulte la declaración al respecto. |