Solucionando problemas de instalação de solicitações python no OS X

0

As tentativas de executar o script python flightaware do teste falhar:

Users-MacBook-Air:FlightAwareXML3 user$ python flightawareXML01.py
Traceback (most recent call last):
  File "flightawareXML01.py", line 9, in <module> import requests   

Tente instalar solicitações via pip falha:

# sudo pip install requests
ImportError: No module named requests
Users-MacBook-Air:FlightAwareXML3 user$ sudo pip install requests
Password:
The directory '/Users/user/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.
The directory '/Users/user/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting requests
  Could not fetch URL https://pypi.python.org/simple/requests/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
  Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests
Users-MacBook-Air:FlightAwareXML3 user$ pip --version

PERGUNTA

O certificado SSL está impedindo as solicitações ?

Aparentemente, o Mac tem duas versões do Python instaladas:

pip 9.0.1 from /Library/Python/2.7/site-packages (python 2.7)
Users-MacBook-Air:FlightAwareXML3 user$ pip3 --version
pip 8.0.2 from /usr/local/lib/python3.5/site-packages (python 3.5)
Users-MacBook-Air:FlightAwareXML3 user$ which python
/usr/bin/python

Tentativa de instalar via pip3:

Users-MacBook-Air:FlightAwareXML3 user$ sudo pip3 install requests
Password:
The directory '/Users/user/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.
The directory '/Users/user/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting requests
  Downloading https://files.pythonhosted.org/packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl (88kB)
    100% |████████████████████████████████| 90kB 94kB/s 
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 135kB 102kB/s 
Collecting certifi>=2017.4.17 (from requests)
  Downloading https://files.pythonhosted.org/packages/7c/e6/92ad559b7192d846975fc916b65f667c7b8c3a32bea7372340bfe9a15fa5/certifi-2018.4.16-py2.py3-none-any.whl (150kB)
    100% |████████████████████████████████| 151kB 130kB/s 
Collecting idna<2.7,>=2.5 (from requests)
  Downloading https://files.pythonhosted.org/packages/27/cc/6dd9a3869f15c2edfab863b992838277279ce92663d334df9ecf5106f5c6/idna-2.6-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 57kB 137kB/s 
Collecting urllib3<1.23,>=1.21.1 (from requests)
  Downloading https://files.pythonhosted.org/packages/63/cb/6965947c13a94236f6d4b8223e21beb4d576dc72e8130bd7880f600839b8/urllib3-1.22-py2.py3-none-any.whl (132kB)
    100% |████████████████████████████████| 135kB 163kB/s 
Installing collected packages: chardet, certifi, idna, urllib3, requests
Successfully installed certifi-2018.4.16 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22
You are using pip version 8.0.2, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Tentativa de executar o script python:

Users-MacBook-Air:FlightAwareXML3 user$ python flightawareXML01.py
Traceback (most recent call last):
  File "flightawareXML01.py", line 9, in <module>
    import requests   # sudo pip install requests
ImportError: No module named requests

Perguntas:

  1. A execução do arquivo .py é executada pelo Python 2.7 ou 3?
  2. Como a causa raiz / ação corretiva pode ser diagnosticada para as falhas de instalação do pip?

ATUALIZAÇÕES

Sucesso executando script python com python3

python3 flightawareXML01.py

Resultados da consulta openSSL do Python 2.7:

Users-MacBook-Air:FlightAwareXML3 user$ python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.0.2g  1 Mar 2016
Users-MacBook-Air:FlightAwareXML3 user$ python -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 0.9.8zh 14 Jan 2016
    
por gatorback 01.05.2018 / 19:10

1 resposta

1

Is the execution of the .py file performed by Python 2.7 or 3?

Como você instalou requests com êxito com pip3 e python flightawareXML01.py indica que requests ainda não foi encontrado, parece razoável supor que o comando python está tentando executar o arquivo .py com o Python 2.7 (você sempre pode usar python -V para verificar a versão).

Para resolver isso, tente usar python3 em vez de python (ou seja, python3 flightawareXML01.py ).

Is the SSL Certificate preventing the requests install?

Parece provável que este não seja um problema de certificado em si (já que o certificado SSL atual para https://pypi.python.org/simple/requests/ parece válido), mas o erro parece estar relacionado ao SSL.

How can the root cause / corrective action be diagnosed for the pip install failures?

O erro que você recebeu:

Could not fetch URL https://pypi.python.org/simple/requests/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping

não parece ter uma conclusão definitiva do que eu poderia dizer, além das versões incorretas ou cifras do protocolo SSL possivelmente sendo usadas entre o cliente ( pip ) e o servidor (com base em pesquisando em torno de tlsv1 alert protocol version ) .

Dito isto, poderá estar interessado nesta pergunta do StackOverflow , como bem como este . Ambos propõem soluções para esse problema (embora, reconhecidamente, as respostas pareçam girar em torno da atualização do OpenSSL / Python).

    
por 02.05.2018 / 05:39

Tags