【发布时间】:2021-07-07 21:21:09
【问题描述】:
我正在尝试运行迁移学习工具包上的培训模块,但似乎无法正确映射我的目录。我省略了之前在 os.environ 和路径名之间的等号。仍然返回错误。我不确定我哪里出错了。
mport json
import os
default_value = '~/LOCAL_PROJECT_DIR'
os.getenv('LOCAL_PROJECT_DIR', default_value)
mounts_file = os.path.expanduser("~/.tlt_mounts.json")
# Define the dictionary with the mapped drives
drive_map = {
"Mounts": [
# Mapping the data directory
{
"source": os.environ["/LOCAL_PROJECT_DIR/data"],
"destination": "/workspace/tlt-experiments"
},
# Mapping the specs directory.
{
"source": os.environ["/LOCAL_PROJECT_DIR/files"],
"destination": os.environ["/workspace/tlt-experiments/specs"]
},
]
}
给出的错误:
KeyError Traceback(最近一次调用最后一次) 在 11 # 映射数据目录 12 { ---> 13 "来源": os.environ["/LOCAL_PROJECT_DIR/data"], 14 "目的地": "/workspace/tlt-experiments" 15 },
~/opt/anaconda3/lib/python3.8/os.py in getitem(self, key) 673,除了 KeyError: 第674章 --> 675 从无引发 KeyError(key) 第676章 677
KeyError: '/LOCAL_PROJECT_DIR/data'
本次更新后我的代码运行流畅:
# Define the dictionary with the mapped drives
drive_map = {
"Mounts": [
# Mapping the data directory
{
"source": "/LOCAL_PROJECT_DIR/data",
"destination": "/workspace/tlt-experiments"
},
# Mapping the specs directory.
{
"source": "/LOCAL_PROJECT_DIR/files",
"destination": "/workspace/tlt-experiments/specs"
},
]
}
谢谢大家!
【问题讨论】:
-
欢迎来到 SO!看起来第 11 行需要阅读
"source": os.environ["LOCAL_PROJECT_DIR"],。你试过了吗? -
谢谢!是的,我做到了。我已经更新了带有新错误的帖子。
标签: python directory formatting syntax-error nvidia