0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

python import 自作モジュール 相対パスの不可解

Posted at

my_package/
├── init.py
├── mod.py
├── sub_package
├── init.py
└── sub_mod.py

sub_modからmodを呼び出す

sub_mod.py
from .. import mod

sub_mod.pyを単体で動かすとエラーになる事がある

対策
root dirに移動してパッケージで実行(my_packageの上に移動)
python -m my_package.sub_package.sub_mod

または、PYTHONPATHを設定 $env:PYTHONPATH="C:\user\xxx\my_package"
sub_mod.py
import mod

とする。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?