python 当在google colab上执行代码时,出现argparse.ArgumentParser()错误

x8diyxa7  于 2023-06-04  发布在  Python
关注(0)|答案(1)|浏览(141)

我不能解决这个错误是因为我们不能在google colab上使用argparse还是有其他的替代方法
代码是:-

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-d", "--data", required=True, help="CSV file with quotes to run the model")
    parser.add_argument("-m", "--model", required=True, help="Model file to load")
    parser.add_argument("-b", "--bars", type=int, default=50, help="Count of bars to feed into the model")
    parser.add_argument("-n", "--name", required=True, help="Name to use in output images")
    parser.add_argument("--commission", type=float, default=0.1, help="Commission size in percent, default=0.1")
    parser.add_argument("--conv", default=False, action="store_true", help="Use convolution model instead of FF")
    args = parser.parse_args()

    prices = data.load_relative(args.data)
    env = environ.StocksEnv({"TEST": prices}, bars_count=args.bars, reset_on_close=False, commission=args.commission,
                            state_1d=args.conv, random_ofs_on_reset=False, reward_on_close=False, volumes=False)

错误是:

usage: ipykernel_launcher.py [-h] -d DATA -m MODEL [-b BARS] -n NAME
                             [--commission COMMISSION] [--conv]
ipykernel_launcher.py: error: the following arguments are required: -d/--data, -m/--model, -n/--name
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2
bakd9h0s

bakd9h0s1#

如果使用colab,请使用args = parser.parse_args(args=[])

相关问题