close

[Solved] Python error: the following arguments are required

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python error: the following arguments are required in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Python error: the following arguments are required Error Occurs?

Today I get the following error Python error: the following arguments are required in python.

How To Solve Python error: the following arguments are required Error ?

  1. How To Solve Python error: the following arguments are required Error ?

    To Solve Python error: the following arguments are required Error When calling argparse with arguments not from sys.argv you've got to call it with

  2. Python error: the following arguments are required

    To Solve Python error: the following arguments are required Error When calling argparse with arguments not from sys.argv you've got to call it with

Solution 1

When calling argparse with arguments not from sys.argv you’ve got to call it with

parser.parse_args(args)

instead of just

parser.parse_args()

Solution 2


If your MAIN isn’t a def / function you can simulate the args being passed in:

if __name__=='__main__':

    # Set up command-line arguments
    parser = ArgumentParser(description="Simple employee shift roster generator.")
    parser.add_argument("constraints_file", type=FileType('r'),
                        help="Configuration file containing staff constraints.")
    parser.add_argument("first_day", type=str,
                        help="Date of first day of roster (dd/mm/yy)")
    parser.add_argument("last_day", type=str,
                        help="Date of last day of roster (dd/mm/yy)") 

    #Simulate the args to be expected...   <--- SEE HERE!!!
    argv = ["",".\constraints.txt", "1/5/13", "1/6/13"]

    # Parse arguments
    args = parser.parse_args(argv[1:])

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read