Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import custom functions in CoLab Notebook #1

Open
harjeeth opened this issue Jun 2, 2018 · 7 comments
Open

Can't import custom functions in CoLab Notebook #1

harjeeth opened this issue Jun 2, 2018 · 7 comments

Comments

@harjeeth
Copy link
Contributor

harjeeth commented Jun 2, 2018

For some reason any linking to images stored in another directory doesn't seem to break, but it does when it comes to custom packages/functions:
image

Any idea on how to solve this?

@gahjelle
Copy link
Member

gahjelle commented Jun 2, 2018

Does it work if you specify the folder as well in the import? I.e. from python.plot_functions import make_plot?

@gahjelle
Copy link
Member

gahjelle commented Jun 2, 2018

Another option might be to explicitly add the python subfolder to sys.path. Something along the lines of

import sys
sys.path.append("python")
from plot_functions import make_plot

Ah, sorry, I see you've already tried this 😊

@gahjelle
Copy link
Member

gahjelle commented Jun 2, 2018

It might also be that the working directory of the notebook is not where you expect? What does

import pathlib
print(pathlib.Path.cwd())

tell you?

@harjeeth
Copy link
Contributor Author

harjeeth commented Jun 2, 2018

@gahjelle this:

import pathlib
print(pathlib.Path.cwd())

gives me:

>>> /content

and

print(sys.path)

is

>>> ['./python', './python', '', '/env/python', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages', '/usr/local/lib/python3.6/dist-packages/IPython/extensions', '/content/.ipython']

@gahjelle
Copy link
Member

gahjelle commented Jun 2, 2018

So the /content folder seems to be where colab puts stuff. You can also do print(list(pathlib.Path.cwd().iterdir())) to see what is inside that folder. Do you see your python file there?

@harjeeth
Copy link
Contributor Author

harjeeth commented Jun 2, 2018

What I see running print(list(pathlib.Path.cwd().iterdir())) is

>>> [PosixPath('/content/datalab'), PosixPath('/content/.forever'), PosixPath('/content/.rnd'), PosixPath('/content/.ipython'), PosixPath('/content/.config'), PosixPath('/content/.cache'), PosixPath('/content/.local')]

@gahjelle
Copy link
Member

gahjelle commented Jun 2, 2018

Ok, I don't see any of your directories there. So it seems quite clear that those are not a part of colab. So something like Patrick's idea of using wget to download it on the fly seems necessary.

Or just include the code in the notebook instead 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants