0
0

get_conf関数のエラーについて

Posted at

エラーの内容

前回の記事で書いたことが間違っていた感じがするので,投稿し直す.

エラー内容
Traceback (most recent call last):
  File "parser.py", line 11, in <module>
    from utils.helpers import get_conf
ModuleNotFoundError: No module named 'utils'

使用環境

今回は ROS は関係ありませんが,一応載せます.

  • 使用PC: Jetson AGX Orin
  • JetPack: 5.1.2
  • CUDA: 11.4
  • cudnn: 8.6
  • python: 3.8
  • tensorflow: 2.12.0
  • ubuntu 20.04
  • ROS noetic
  • 仮想環境venvを使用

解決方法: utils を使用する.

まずはutilsをインストール

pathは/home/usr_name/catkin_ws/venv/lib/python3.8/site-packages/utilsでした.

インポート
pip3 install utils

utils内のhelpers.pyget_conf関数を勝手に挿入.(今回はyamlファイルを読み込無用に作成)

helper.py
import yaml

def get_conf(config_path):
    """YAML形式の設定ファイルを読み込んでその内容を返す関数

    Args:
        config_path (str): 設定ファイルのパス

    Returns:
        dict: 設定ファイルの内容を含む辞書
    """
    with open(config_path, 'r') as config_file:
        config = yaml.safe_load(config_file)
    return config

そうしたら,path を通してインポート.
実行したらできるはず.

実行したいスクリプト
import sys
sys.path.append('/home/usr_name/catkin_ws/venv/lib/python3.8/site-packages/utils')

from utils.dicts.helpers import get_conf

おわりに

また分かり次第メモしていきます.

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