2016-07-14 25 views
15

Quando eseguo !pip install geocoder in Jupyter Notebook ottengo lo stesso output di pip install geocoder nel terminale ma il pacchetto geocoder non è disponibile quando provo a importarlo.Installazione di un pacchetto pip dall'interno di un Notebook Jupyter non funzionante

sto usando Ubuntu 14.04, Anaconda 4.0.0 e 8.1.2 pip

geocoder Installazione:

!pip install geocoder 

The directory '/home/ubuntu/.cache/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 '/home/ubuntu/.cache/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 geocoder 
    Downloading geocoder-1.15.1-py2.py3-none-any.whl (195kB) 
    100% |████████████████████████████████| 204kB 3.2MB/s 
Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.7/dist-packages (from geocoder) 
Requirement already satisfied (use --upgrade to upgrade): ratelim in /usr/local/lib/python2.7/dist-packages (from geocoder) 
Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python2.7/dist-packages (from geocoder) 
Requirement already satisfied (use --upgrade to upgrade): click in /usr/local/lib/python2.7/dist-packages (from geocoder) 
Requirement already satisfied (use --upgrade to upgrade): decorator in /usr/local/lib/python2.7/dist-packages/decorator-4.0.10-py2.7.egg (from ratelim->geocoder) 
Installing collected packages: geocoder 
Successfully installed geocoder-1.15.1 

quindi provare a importarlo:

import geocoder 

--------------------------------------------------------------------------- 
ImportError        Traceback (most recent call last) 
<ipython-input-4-603a981d39f2> in <module>() 
----> 1 import geocoder 

ImportError: No module named geocoder 

Ho anche provato spegnere il notebook e riavviarlo senza fortuna.

Modifica: ho trovato che l'utilizzo del terminale installa il pacchetto geocoder in /home/ubuntu/.local/lib/python2.7/site-packages e l'utilizzo di un notebook lo installa in/usr/local/lib/python2. 7/dist-packages che non si trova nel percorso. sys.path.append('/usr/local/lib/python2.7/dist-packages') risolve il problema per la sessione corrente.

Quindi, come posso modificare permanentemente il percorso o indicare a pip dove installare il geocoder?

+1

Quelli sono Python 2 pacchetti. Il tuo notebook usa un kernel Python 2 o un kernel Python 3? – nitind

+0

Utilizzo di Python 2 –

+0

['PYTHONPATH'] (https://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH) – Alik

risposta

0

Provate utilizzando alcune shell magia: %% sh %%sh pip install geocoder fatemi sapere se funziona, grazie

-3

Uso PIP2 ha funzionato per me:

!pip2 install geocoder 
... 
import geocoder 
g = geocoder.google('Mountain View, CA') 
g.latlng 
[37.3860517, -122.0838511] 
0
conda create -n py27 python=2.7 ipykernel 

source activate py27 

pip install geocoder 
9
! pip install --user <package> 

('!' The dice il notebook per eseguire la cella come un comando di shell)

0

Opzione alternativa: è anche possibile creare una cella bash in jupyter utilizzando kernel bash e poi pip install geocoder. Che dovrebbe funzionare

1

Nel quaderno jupyter sotto python 3.6, la seguente riga funziona:

!source activate py36;pip install <...> 
Problemi correlati