Oggi ho installato l'ultimo Ubuntu Gnome e stavo configurando la mia macchina per il lavoro relativo alla scienza dei dati. Quando ho provato a installare tensorflow-gpu, mi sono imbattuto in un arresto anomalo da pip3:
[email protected]:~/Desktop$ pip3
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 33, in vendored
    __import__(vendored_name, globals(), locals(), level=0)
ImportError: No module named 'pip._vendor.pkg_resources'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 13, in <module>
    from pip.exceptions import InstallationError, CommandError, PipError
  File "/usr/lib/python3/dist-packages/pip/exceptions.py", line 6, in <module>
    from pip._vendor.six import iteritems
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 75, in <module>
    vendored("pkg_resources")
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
    __import__(modulename, globals(), locals(), level=0)
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2927, in <module>
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2913, in _call_aside
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2952, in _initialize_master_working_set
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 956, in subscribe
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2952, in <lambda>
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2515, in activate
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2097, in declare_namespace
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2047, in _handle_ns
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2066, in _rebuild_mod_path
AttributeError: '_NamespacePath' object has no attribute 'sort'
 
 Ho provato a eliminare python3-pip e reinstallare, ma non funziona ancora. Ottengo quanto sopra semplicemente eseguendo pip3 nel terminale e premendo INVIO.
Qualche idea?
EDIT:anche i due percorsi sono diversi per pip e pip3:
[email protected]:~$ which pip
/home/me/.local/bin/pip
[email protected]:~$ which pip3
/usr/bin/pip3
 Risposta accettata:
L'ho risolto creando un nuovo ambiente virtuale
-  
Un nuovo ambiente virtuale può essere creato da:
python3 -m venv /tmp/newvenv -  
Quindi ho verificato se pip funziona correttamente nel nuovo ambiente virtuale:
cd /tmp/newvenv/bin ./pip3 
Questo mi ha dato il messaggio normale come nel seguente:
 Utilizzo:
 pip [opzioni]
Comandi:
install Installa pacchetti.
scarica Scarica pacchetti.
…
Tuttavia, pip3 ha ancora fallito.
    pip3
 Questo mi dava ancora il messaggio di errore.
Quindi ho deciso di copiare le versioni funzionanti di pip nella home directory. Per i due passaggi seguenti (n. 3 e n. 4) potresti voler conservare le copie di backup.
-  
Ho sovrascritto pip e pip-9.0.1.dist-info dall'ambiente virtuale alla home directory:
cp -r /tmp/newvenv/lib/python3.5/site-packages/pip ~/.local/lib/python3.5/site-packages/ cp -r /tmp/newvenv/lib/python3.5/site-packages/pip-9.0.1.dist-info ~/.local/lib/python3.5/site-packages/ -  
Ho anche copiato i seguenti due file:
cp /tmp/newvenv/lib/python3.5/site-packages/pkg_resources/__init__.py ~/.local/lib/python3.5/site-packages/pkg_resources/ cp /tmp/newvenv/lib/python3.5/site-packages/pkg_resources/py31compat.py ~/.local/lib/python3.5/site-packages/pkg_resources/ 
Dopo questi passaggi pip3 funziona bene nel mio caso.
Correlati:come ripristinare i repository predefiniti?