2015-04-30 15 views
5

Ho configurato un server ipython per altre persone (nel reparto aziendale) per avere la possibilità di imparare e lavorare con python.Carica dati locali nel server notebook IPython

Ora mi chiedo come le persone possono caricare i propri dati locali nella sessione del notebook ipython sul server remoto. C'è un modo per fare questo?

+0

Quale versione di 'IPython' stai usando? Può essere aggiornato a 'jupyter' – Amit

+0

Sto usando jupyter. Quindi c'è un modo per caricare i dati? –

+0

Basta eseguire 'jupyter' dalla directory (o dal suo genitore) da cui si desidera ottenere i dati. – Amit

risposta

5

Poiché è stato installato jupyter, tutti gli utenti devono vedere i file/le cartelle nella directory di avvio jupyter e nella relativa sottodirectory. Il pulsante new sul notebook jupyter può essere utilizzato per creare un nuovo file/cartella o anche un terminale. I file possono essere caricati utilizzando la funzione drag-drop o click here evidenziata di seguito.

enter image description here

+0

Ma come mi aiuta a caricare file di dati? –

+1

@MichaelHecht - È possibile trascinare e rilasciare i file su un blocco note o cercare il file da caricare utilizzando il tasto 'clicca qui '. Vedi evidenziazione nello screenshot aggiornato. – Amit

+0

Ah ... ok ... sono nei prossimi giorni non in ufficio, ma lo controllerò il prima possibile. Grazie in anticipo. –

3

Un modo alternativo per raggiungere questo obiettivo con python:

def jupyter_upload(token, filePath, resourceDstPath, jupyterUrl='http://localhost:8888'): 
    """ 
     Uploads File to Jupyter Notebook Server 
     ---------------------------------------- 
     :param token: 
      The authorization token issued by Jupyter for authentification 
      (enabled by default as of version 4.3.0) 
     :param filePath: 
      The file path to the local content to be uploaded 

     :param resourceDstPath: 
      The path where resource should be placed. 
      The destination directory must exist. 

     :param jupyterUrl: 
      The url to the jupyter server. Default value is typical localhost installation. 

     :return: server response 

    """ 
    import os 
    import base64 
    import urllib 
    import json 
    import requests 
    dstPath = urllib.quote(resourceDstPath) 
    dstUrl = '%s/api/contents/%s' % (jupyterUrl, dstPath) 
    fileName = filePath[1 + filePath.rfind(os.sep):] 
    headers = {} 
    headers['Authorization'] = 'token '+token 
    with open(filePath, 'r') as myfile: 
     data=myfile.read() 
     b64data=base64.encodestring(data) 
     body = json.dumps({ 
      'content':b64data, 
      'name': fileName, 
      'path': resourceDstPath, 
      'format': 'base64', 
      'type':'file' 
     }) 
     return requests.put(dstUrl, data=body, headers=headers, verify=True) 
0

Se si tratta di un file di testo, creare un file vuoto, modificarlo e quindi copiare/incollare il contenuto ..

si può fare questo per bypassare il vincolo di 25 MB

0

Una volta che si esegue jupyter ipython notebook, fare clic su nuovi -> Vai a terminal e poi semplicemente eseguire il seguente comando:

You can pass your files **url** here and get your file uploaded on the server and you are ready to go. Otherwise directly drag a file or upload the file from the <code>upload</code> button.

È possibile passare i file url qui e ottenere il file caricato sul server e si è pronti ad andare. Altrimenti trascina direttamente un file o carica il file dal pulsante .

Problemi correlati