{"record":{"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/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/commands/search.py#L38-L74","documentation":"Raised by SearchCommand.run() when no positional arguments are supplied. pip search requires at least one search term; with an empty args list it cannot form a query against the package index and aborts immediately.","triggerScenarios":"Running `pip search` with no arguments, or passing only options (e.g. `pip search --index https://...`) without a query string.","commonSituations":"Typing `pip search` and pressing enter; scripts that build a search command but pass an empty variable as the query.","solutions":["Provide a search term: `pip search <query>`.","If building the command dynamically, validate the query is non-empty before invoking pip.","Note: PyPI deprecated the XML-RPC search endpoint, so even with a query this command may fail at the network layer (see error 44)."],"exampleFix":"# before\npip search\n# after\npip search requests","handlingStrategy":"validation","validationCode":"def run_pip_search(query: str) -> list[str]:\n    if not query or not query.strip():\n        raise ValueError('pip search requires a non-empty query')\n    return ['pip', 'search', query]\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the query is non-empty before invoking pip search.","Note pip search is effectively dead on PyPI; prefer the JSON API."],"tags":["pip","search","cli","arguments"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}