0

I am new to Google cloud and datalab. I struggled to get it up and running. I was wondering how I could just import user-written .py files within datalab notebook.

I tried using "pip install git+~~". It installs, but it seems like it is installing in the wrong directory or something. I was not able to import it.

Please help me out.

Btw, I wonder how I could "pip install git+~~" for private repo. Notebook isn't interactive. I tried echo userid | echo password | pip install git+~

Thank you!

  • Not sure if this helps you at all: http://stackoverflow.com/questions/33174293/adding-python-libraries-to-google-datalab-environment – kayleeFrye_onDeck Sep 19 '16 at 20:32
  • This might help as well: http://stackoverflow.com/questions/33165443/how-to-add-private-python-module-to-google-datalab?rq=1 – kayleeFrye_onDeck Sep 19 '16 at 21:00
  • 1
    @kayleeFrye_onDeck Thank you for the reply. I have already checked them out. That's how I tried the thing I mentioned. I am asking more details on the second posts, how I would import it once installed. Thanks! – Bosuk Hong Sep 19 '16 at 21:06

1 Answers1

1

Assuming the python package is created correctly, the import should work after installing the python package.

To install a package from Github (using the xrld package as an example), run either

!pip install https://github.com/python-excel/xlrd/archive/master.zip
import xlrd

or

!pip install git+http://github.com/python-excel/xlrd.git
import xlrd

I ran through the process of creating a minimal python package and was able to import it successfully in Google Cloud Datalab with:

import funniest
print funniest.joke()

After installing it with:

!cd funniest && pip install .

You can check the install location by running the following code:

>> funniest.__file__
'/usr/local/lib/python2.7/dist-packages/funniest/__init__.pyc'

Could you try also try creating a minimal python package and see if that works? You may be able to spot a subtle the difference between your package and the minimal package.

Anthonios Partheniou
  • 1,699
  • 1
  • 15
  • 25