{"id":"ade9a1a45f2d52d8","repo":"pypa/pip","slug":"missing-required-argument-search-query","errorCode":null,"errorMessage":"Missing required argument (search query).","messagePattern":"Missing required argument \\(search query\\)\\.","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/commands/search.py","lineNumber":56,"sourceCode":"    usage = \"\"\"\n      %prog [options] <query>\"\"\"\n    ignore_require_venv = True\n\n    def add_options(self) -> None:\n        self.cmd_opts.add_option(\n            \"-i\",\n            \"--index\",\n            dest=\"index\",\n            metavar=\"URL\",\n            default=PyPI.pypi_url,\n            help=\"Base URL of Python Package Index (default %default)\",\n        )\n\n        self.parser.insert_option_group(0, self.cmd_opts)\n\n    def run(self, options: Values, args: list[str]) -> int:\n        if not args:\n            raise CommandError(\"Missing required argument (search query).\")\n        query = args\n        pypi_hits = self.search(query, options)\n        hits = transform_hits(pypi_hits)\n\n        terminal_width = None\n        if sys.stdout.isatty():\n            terminal_width = shutil.get_terminal_size()[0]\n\n        print_results(hits, terminal_width=terminal_width)\n        if pypi_hits:\n            return SUCCESS\n        return NO_MATCHES_FOUND\n\n    def search(self, query: list[str], options: Values) -> list[dict[str, str]]:\n        index_url = options.index\n\n        session = self.get_default_session(options)\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/commands/search.py#L38-L74","documentation":"Raised as CommandError in SearchCommand.run() at search.py:55-56 when no positional arguments are supplied. 'pip search' requires at least one search term to query the PyPI XMLRPC index; an empty query is invalid.","triggerScenarios":"Running 'pip search' with no arguments. The check 'if not args' at search.py:55 fires when the args list is empty.","commonSituations":"Typing 'pip search' alone expecting help; a shell alias that strips arguments; scripting that passes an empty variable as the query.","solutions":["Provide at least one search term: 'pip search <query>'.","If your query comes from a variable, guard the call so it only runs when the variable is non-empty.","Run 'pip search --help' to see usage."],"exampleFix":"# before\npip search\n# after\npip search requests","handlingStrategy":"validation","validationCode":"import sys\nquery = [a for a in sys.argv[1:] if not a.startswith('-')]\nif not query:\n    print('ERROR: pip search requires a non-empty query', file=sys.stderr)\n    sys.exit(2)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a non-empty positional query to pip search.","Guard shell wrappers that interpolate variables so empty values skip the call."],"tags":["pip","search","missing-argument","cli"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}