LoginSignup
0
0

More than 1 year has passed since last update.

【備忘録】同じ階層にあるpyファイルをipynb上でimportできなかった

Posted at

自分用のメモです。

問題

jupyterlabでipynbを動かしていて、同じ階層にあるmodule.pyという自作モジュールからEarlyStoppingという関数をimportしたかったが、

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-20-5c119319e129> in <module>
----> 1 from module import EarlyStoppping

ImportError: cannot import name 'EarlyStoppping'

と出て動かなかった。

解決策

ipynb上で自作モジュールを読み込みたいときは、対象のpyファイルにmodule.pyという名前を付けないほうが良いっぽく、my_utils.pyにしたらインポートできた。

ディレクトリ構造

202207/
 ├ test.pynb
 ├ module.py

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0