3

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
7
  • 1
    is the whole code is in a seperate file, and u r running it from the cli right? Commented Sep 29, 2021 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. Commented Sep 29, 2021 at 13:36
  • 1
    argparse parses sys.argv, which contains commandline values. The ones provided to the server (ipykernel) aren't relevant. Commented Sep 29, 2021 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. Commented Sep 29, 2021 at 13:57
  • you can't use argparse or any other commandline parser in a notebook. Commented Sep 29, 2021 at 14:06

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Can you elaborate?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.