How to import python files in google colaboratory?

后端 未结 4 1995
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 15:33

I am trying to run my program on Google Colab; where my code make use of .py files written seprately.

In normal system I have all files inside one folder and it wor

4条回答
  •  时光取名叫无心
    2021-01-02 16:11

    Something I've used when I have multiple python scripts and want to automatically import through code is to set it up as a package and clone from the repo.

    First set up the scripts in a repo with a setup.py and __init__.py files (obviously).

    Then add this to the top of your notebook:

    !rm -rf   # in case you need to refresh after pushing changes 
    !git clone https://github.com//.git
    

    Then install the package:

    !pip install ./
    

    Now conveniently import functions or whatever:

    from . import 
    

提交回复
热议问题