我想运行一个python脚本,比如在Win 10中运行Anaconda的jupyter notebook中的train_rnn_wdcnn_loads.py
,但我经常收到以下错误:
ipykernel_launcher.py: error: the following arguments are required: -data_path
- (我是Python新手,还在研究argparse是如何工作的)*
代码为:
import argparse
parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
parser.add_argument('-data_path', required=True)
args = parser.parse_args()
我曾尝试让它与以下内容一起工作:
parser.add_argument('-data_path', required=True, default="C:\\Users\\Firdaus\\Desktop\\data")
或从this answer:
args = parser.parse_args(data_path="C:\\Users\\Firdaus\\Desktop\\data")
但还是不行。
当我通过命令行python train_rnn_wdcnn_loads.py -data_path C:\\Users\\Firdaus\\Desktop\\data
运行脚本时,它工作正常,但在另一个python脚本中仍然面临错误。
Using TensorFlow backend.
1614364082.0161884
loading data ...
Traceback (most recent call last):
File "train_rnn_wdcnn_loads.py", line 107, in <module>
source_data = CWRUBearingData(data_path, experiment, source,
File "C:\Users\Firdaus\AppData\Local\Programs\Python\Python38\lib\site-packages\utils\cwru_data_loader.py", line 114, in __init__
for l in self.loads:
TypeError: 'NoneType' object is not iterable
如何运行脚本而不出错?
1条答案
按热度按时间t98cgbkg1#
如果您在代码中输入(required = True),它将忽略(默认值="C:\Users\Firdaus\Desktop\data")
这应该行得通: