0

I am not able to solve this error is it that we cannot use argparse on google colab or there is some alternative to it

The code is:-

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)

The Error is :

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
Ahead
  • 1
  • 1
    is the whole code is in a seperate file, and u r running it from the cli right? – Ghost Ops Sep 29 '21 at 13:25
  • How are you running the code? The error message is pretty clear: you defined several options as required, but apparently are not providing all of them. – chepner Sep 29 '21 at 13:36
  • 1
    `argparse` parses `sys.argv`, which contains commandline values. The ones provided to the server (ipykernel) aren't relevant. – hpaulj Sep 29 '21 at 13:43
  • I have created different .py files and the data, model, bars are created in those while i am running the new created file by importing them on new colab notebook. – Ahead Sep 29 '21 at 13:57
  • you can't use argparse or any other commandline parser in a notebook. – hpaulj Sep 29 '21 at 14:06
  • is there any way i could rewrite it for notebook as i dont think my pc could handle this model? – Ahead Sep 29 '21 at 14:14
  • I guess you can try to use `parser.parse_args()` in a way it is suggested [here](https://stackoverflow.com/a/59893449/6818619). In my work with notebooks I usually just call needed `.py` files like `!python my_file.py -arg1`. – ans Sep 30 '21 at 06:32

1 Answers1

0

Use args = parser.parse_args(args=[]) if you are using colab.

mozway
  • 194,879
  • 13
  • 39
  • 75
TensoR
  • 1