Resolver errores comunes al instalar la biblioteca Scrapy en Python

Tabla de contenido

1. Error al informar sobre el comando pip3

2. Se produce un error al ejecutar scrapy (se produce un error en el módulo OpenSSL en Python3)

3. Ocurre un error al desinstalar pyopenssl


Dado que la biblioteca Scrapy tendrá problemas de compatibilidad en Windows, lo siguiente trata sobre su instalación en un sistema Linux.

1. Error al informar sobre el comando pip3

Código de error:

error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.11/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

Solución: agregue el parámetro --break-system-packages después del comando original

Debido a que scrapy se puede usar directamente como comando, también podemos ingresar un comando no existente en la terminal y le pedirá que lo instale.

A veces pip3 no funciona, también podemos cambiar a pipx o apt install python3-nombre del archivo para instalar

pipx install scrapy

apt install python3-scrapy

 

2. Se produce un error al ejecutar scrapy (se produce un error en el módulo OpenSSL en Python3)

Código de error:

Traceback (most recent call last):
  File "/usr/bin/scrapy", line 33, in <module>
    sys.exit(load_entry_point('Scrapy==2.10.0', 'console_scripts', 'scrapy')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/scrapy", line 25, in importlib_load_entry_point
    return next(matches).load()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/metadata/__init__.py", line 202, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
   ...
 AttributeError: module 'lib' has no attribute 'SSL_CTX_set_ecdh_auto'

Este es un error en el módulo OpenSSL en Python3. Necesitamos desinstalarlo y reinstalarlo.

Solución:

pip3 uninstall pyopenssl
pip3 install pyopenssl

 Probé algunos comandos y descubrí que no funcionaban.

3. Ocurre un error al desinstalar pyopenssl

Código de error:

Found existing installation: pyOpenSSL 21.0.0
Not uninstalling pyopenssl at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'pyOpenSSL'. No files were found to uninstall.

Requirement already satisfied: pyopenssl in /usr/lib/python3/dist-packages (21.0.0)

Solución:

Busque la ruta a la carpeta, elimine el directorio pyOpenSSL-21.0.0 directamente y luego vuelva a instalarlo.

Esta carpeta está en /usr/lib/python3/dist-packages/

eliminar carpeta completa

Reinstale pyopenssl usando el comando

pip3 install pyopenssl --break-system-packages

Después de una instalación exitosa, ingrese el comando scrapy

Como se muestra a continuación, significa que la biblioteca se ha instalado correctamente.

También podemos ingresar ipython3 para verificar:

ipython es un shell interactivo de Python, que es mucho más fácil de usar que el shell de Python predeterminado: admite finalización automática de variables, sangría automática, admite comandos de shell bash y tiene muchas funciones y funciones integradas útiles.

Siempre que la biblioteca se pueda importar correctamente y no se informen errores, se demuestra que la instalación se ha realizado correctamente.

 

Supongo que te gusta

Origin blog.csdn.net/Myon5/article/details/133176596
Recomendado
Clasificación