Hydrogen: Running file on remote kernel which imports others local file

Created on 7 Mar 2017  路  2Comments  路  Source: nteract/hydrogen

Sorry for dumping this here, did not find any appropriate place to ask this question

I am trying to use Hydrogen in atom to run my local python and R code. I have installed Jupyter notebook and kernel (IPython and R) on AWS EC2 instance using Anaconda (without authentication required) and it's running fine.

Now when i connect remote server from menu _Hydrogen->Connect to remote kernel_ and Run code snippet, It executed as expected and produces desire result.

For eg this below code runs proper

import numpy as np
import matplotlib.pyplot as plt
X = [0,1]
Y = [0,2]
U = [1,3]
V = [2,2]
plt.quiver(X, Y, U, V, angles='xy', scale_units='xy', scale=1)
plt.xlim([0,6])
plt.ylim([0,6])

But when i import another local file in file which i am running it gives me error that module is not found.

for example say i have file name cal.py

def addition(a, b):
    result = a + b
    return result

def negation(a, b):
    result = a - b
    return result

And second file which i am running using kernel is run.py

from cal import addition, negation
print (addition(2,3))
print (negation(3,2))

It give me error as below

ImportError                               Traceback (most recent call last)
<ipython-input-1-43621ff7e35f> in <module>()
----> 1 from cal import addition, negation
     2
     3 print (addition(2,3))
     4 print (negation(3,2))

ImportError: No module named 'cal'

I understand that in first example imported module numpy and matplotlib are already installed my EC2 sever while installing with Anaconda so kernel is able to local and import those module.

I also understand in second example the cal.py is not present on Jupyter server so kernel can't local and import that module.

As i understand Hydrogen (correct me if i am wrong here) it picks up the code from file which is run (block or selected code ) and sends it raw code to kernel and than kernel executes same code in it's sever environment and context and returns result which hydrogen displays. So in second example code it will obviously will not find cal.py on sever

How should i approach if i want to run files like in second example which imports other files from atom editor ? My question is more of how can i tackle this or it is know problem (I won't call this is a issue here)

Any advice would help. Thanks guys !!!

Most helpful comment

I use this kind of remote workflow all the time, and all of the solutions I found so far rely on copying files between local and remote computers.

My current workflow is to use the remote-sync atom package, which essentially runs scp but provides some additional editor integration. This way I can copy over all of my code files before running everything.

In the past, I've also tried an alternative workflow where I mount the remote filesystem over sshfs, so any file changes are automatically synchronized with the remote end. Sadly I found that sshfs on Mac doesn't play well with frequent switching of wifi networks or network disconnects -- but it's still a good option if your internet connection is stable.

There are probably a number of other file-copying-based workflows that would also achieve the same effect.

All 2 comments

I use this kind of remote workflow all the time, and all of the solutions I found so far rely on copying files between local and remote computers.

My current workflow is to use the remote-sync atom package, which essentially runs scp but provides some additional editor integration. This way I can copy over all of my code files before running everything.

In the past, I've also tried an alternative workflow where I mount the remote filesystem over sshfs, so any file changes are automatically synchronized with the remote end. Sadly I found that sshfs on Mac doesn't play well with frequent switching of wifi networks or network disconnects -- but it's still a good option if your internet connection is stable.

There are probably a number of other file-copying-based workflows that would also achieve the same effect.

@PradeepJaiswar I agree with @nikitakit that you will need to use some way of syncing files between your local and remote machines. Feel free to reply if you have any other questions.

Was this page helpful?
0 / 5 - 0 ratings