Fehlerbehebung bei der Installation von Python-Anforderungen unter OS X

884
gatorback

Versuche, ein Beispiel für ein Flug-Python-Skript auszuführen, schlagen fehl:

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

Der Versuch, Anforderungen über Pip zu installieren , schlägt fehl:

# 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 

FRAGE

Verhindert das SSL-Zertifikat die Anforderungen? Installation von ?

Anscheinend hat der Mac zwei Versionen von Python installiert:

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 

Versuch, über Pip3 zu installieren:

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. 

Versuchen Sie, ein Python-Skript auszuführen:

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 

Fragen:

  1. Wird die .py-Datei von Python 2.7 oder 3 ausgeführt?
  2. Wie kann die Ursache / Korrekturmaßnahme für die Pip-Installation festgestellt werden?

AKTUALISIERUNG

Erfolgreiche Ausführung von Python-Skript mit Python3

python3 flightawareXML01.py 

OpenSSL-Abfrageergebnisse von 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 
0

1 Antwort auf die Frage

1
Anaksunaman

Wird die .py-Datei von Python 2.7 oder 3 ausgeführt?

Da Sie requestserfolgreich installiert haben pip3und python flightawareXML01.pyangeben, dass requestsimmer noch nicht gefunden wird, ist es vernünftig anzunehmen, dass Ihr pythonBefehl versucht, Ihre .pyDatei mit Python 2.7 auszuführen (Sie können immer python -Vdie Version überprüfen).

Um dies zu beheben, verwenden Sie python3lieber als python(ie python3 flightawareXML01.py).

Verhindert das SSL-Zertifikat die requestsInstallation?

Es ist wahrscheinlich, dass dies kein Zertifikatproblem an sich ist (da das aktuelle SSL-Zertifikat für https://pypi.python.org/simple/requests/gültig scheint), aber der Fehler scheint sich auf SSL zu beziehen.

Wie kann die Ursache / Abhilfemaßnahme für die pip installFehler diagnostiziert werden ?

Der Fehler, den Sie erhalten haben:

URL https://pypi.python.org/simple/requests/ konnte nicht abgerufen werden: Beim Bestätigen des SSL-Zertifikats ist ein Problem aufgetreten: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] Version des tlsv1-Warnprotokolls (_ssl.c: 590) - Überspringen

Ich hatte anscheinend keine eindeutige Schlussfolgerung aus dem, was ich feststellen konnte, außer den falschen SSL-Protokollversionen oder Chiffren, die möglicherweise zwischen dem Client ( pip) und dem Server (basierend auf Googling tlsv1 alert protocol version) verwendet wurden.

Das heißt, Sie könnten an dieser StackOverflow-Frage ebenso interessiert sein wie an dieser . In beiden Fällen werden Abhilfemaßnahmen für dieses Problem vorgeschlagen (obwohl sich die Antworten offenbar hauptsächlich um die Aktualisierung von OpenSSL / Python drehen).