GoogleCloudPlatform / python-docs-samples

Code samples used on cloud.google.com
Apache License 2.0
7.47k stars 6.45k forks source link

test.py: error: the following arguments are required: path #1001

Closed UmairPar closed 5 years ago

UmairPar commented 7 years ago

Hey guys,

So I am new to python and maybe asking a simple question. I wanted to use the google API to do speech to text for audio files longer than a minute. So I copied and pasted the code into python and I get the error:

usage: test.py [-h] path test.py: error: the following arguments are required: path An exception has occurred, use %tb to see the full traceback.

SystemExit: 2

C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py:2889: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D. warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

When I do the traceback I get this:

Traceback (most recent call last):

File "", line 1, in runfile('C:/Users/MGMT/.spyder-py3/test.py', wdir='C:/Users/MGMT/.spyder-py3')

File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile execfile(filename, namespace)

File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/MGMT/.spyder-py3/test.py", line 82, in args = parser.parse_args()

File "C:\ProgramData\Anaconda3\lib\argparse.py", line 1730, in parse_args args, argv = self.parse_known_args(args, namespace)

File "C:\ProgramData\Anaconda3\lib\argparse.py", line 1762, in parse_known_args namespace, args = self._parse_known_args(args, namespace)

File "C:\ProgramData\Anaconda3\lib\argparse.py", line 1997, in _parse_known_args ', '.join(required_actions))

File "C:\ProgramData\Anaconda3\lib\argparse.py", line 2389, in error self.exit(2, _('%(prog)s: error: %(message)s\n') % args)

File "C:\ProgramData\Anaconda3\lib\argparse.py", line 2376, in exit _sys.exit(status)

SystemExit: 2

What should I do?

theacodes commented 7 years ago

Hi @UmairPar, you should run the script directly with python <script.py>.

karchuli commented 6 years ago

Hey, I am getting the same error. Running directly with python

Using TensorFlow backend usage: predict.py [-h] location predict.py: error: the following arguments are required: location

harini20 commented 6 years ago

plate_recognition.py: error: the following arguments are required: --api, FILE what does this error mean? Do I need to provide my file name? Below is the line of code: parser.add_argument('FILE', help='Path to video.')

rampyg commented 6 years ago

Arguments are passed by adding two leading hyphens. So, when it says

following arguments are required: example_arg

your code should be parser.add_argument('--example_arg', 'arg1'). Note the two leading hyphens --

engelke commented 5 years ago

The issues seem to have been addressed in comments above.

sabeer1486 commented 4 years ago

Hi friends So I am new to python and maybe asking a simple question. this errors are occured in my code. ERROR:the following arguments are required: audio_path, target_path

the code is here. """ A utility script used for converting audio samples to be suitable for feature extraction """

import os.path

def convert_audio(audio_path, target_path, remove=False): """This function sets the audio audio_path to:

def convert_audios(path, target_path, remove=False): """Converts a path of wav files to:

if name == "main": import argparse parser = argparse.ArgumentParser(description="""Convert ( compress ) wav files to 16MHz and mono audio channel ( 1 channel ) This utility helps for compressing wav files for training and testing""") parser.add_argument("audio_path", help="Folder that contains wav files you want to convert") parser.add_argument("target_path", help="Folder to save new wav files") parser.add_argument("-r", "--remove", type=bool, help="Whether to remove the old wav file after converting", default=False)

args = parser.parse_args()
audio_path = args.audio_path
target_path = args.target_path

if os.path.isdir(audio_path):
    if not os.path.isdir(target_path):
        os.makedirs(target_path)
        convert_audios(audio_path, target_path, remove=args.remove)
elif os.path.isfile(audio_path) and audio_path.endswith(".wav"):
    if not target_path.endswith(".wav"):
        target_path += ".wav"
    convert_audio(audio_path, target_path, remove=args.remove)
else:
    raise TypeError("The audio_path file you specified isn't appropriate for this operation")