{"record":{"id":"104129409dea5ace","repo":"puppetlabs/puppet","slug":"cannot-resolve-pip-version","errorCode":null,"errorMessage":"Cannot resolve pip version","messagePattern":"Cannot resolve pip version","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/package/pip.rb","lineNumber":58,"sourceCode":"      [\"pip.exe\"]\n    else\n      %w[pip pip-python pip2 pip-2]\n    end\n  end\n\n  def self.pip_version(command)\n    version = nil\n    execpipe [quote(command), '--version'] do |process|\n      process.collect do |line|\n        md = line.strip.match(/^pip (\\d+\\.\\d+\\.?\\d*).*$/)\n        if md\n          version = md[1]\n          break\n        end\n      end\n    end\n\n    raise Puppet::Error, _(\"Cannot resolve pip version\") unless version\n\n    version\n  end\n\n  # Return an array of structured information about every installed package\n  # that's managed by `pip` or an empty array if `pip` is not available.\n  def self.instances(target_command = nil)\n    if target_command\n      command = target_command\n      validate_command(command)\n    else\n      command = provider_command\n    end\n\n    packages = []\n    return packages unless command\n\n    command_options = ['freeze']","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/package/pip.rb#L40-L76","documentation":"pip.rb:58 (pip_version): the provider discovers the pip version by running `<command> --version` and matching /^pip (\\d+\\.\\d+\\.?\\d*)/; if no output line matches, it raises Puppet::Error 'Cannot resolve pip version'. The version gates behavior (e.g. which list/install flags are safe), so an unparseable version string aborts gem... pip package management before any operation.","triggerScenarios":"A pip package resource (or instances enumeration) where the configured pip command's --version output does not start with 'pip x.y[.z]': a wrapper/virtualenv shim that prints extra banners, a pip so old it formats differently, a broken install where --version exits non-zero or prints to stderr only, or a command that is actually pipx/uv/conda masquerading as pip.","commonSituations":"pyenv/rvm-style shims that prepend output; customized corporate wrappers around pip; pip invoked through `python -m pip` with unusual stdout; Windows or localized environments altering the banner; leftover empty pip scripts after a python upgrade.","solutions":["Run `<pipcmd> --version` yourself exactly as puppet does; the first line must look like 'pip 23.2.1 from ...'.","Point the provider at a real pip executable (absolute path to the venv's bin/pip or /usr/bin/pip3) instead of a shim on PATH.","Upgrade/reinstall the broken pip (`python -m pip install -U pip`) so --version output is standard.","If you use pipx/uv/conda tooling, manage those environments with their own providers/execs, not the pip provider."],"exampleFix":"# before\npackage { 'requests': ensure => installed, provider => 'pip' }  # pipcmd is a broken shim\n\n# after\n# pin the real interpreter's pip\npackage { 'requests': ensure => installed, provider => 'pip', install_options => ['--index-url', 'https://internal/simple'] }\n# and ensure `puppet resource pip pipcmd=/usr/bin/pip3` (or PATH) resolves to a genuine pip","handlingStrategy":"validation","validationCode":"# the exact parse the provider performs\nout = `#{pip_cmd} --version`\nok = out.lines.any? { |l| l.strip =~ /^pip (\\d+\\.\\d+\\.?\\d*)/ }\nraise \"puppet cannot parse '#{pip_cmd} --version' output\" unless ok","typeGuard":"def puppet_parseable_pip?(cmd)\n  `#{cmd} --version 2>&1`.match(/^pip (\\d+\\.\\d+\\.?\\d*)/) ? true : false\nrescue Errno::ENOENT\n  false\nend","tryCatchPattern":"begin\n  Puppet::Type.type(:package).provider(:pip).instances\nrescue Puppet::Error => e\n  raise unless e.message == 'Cannot resolve pip version'\n  # re-point provider at a known-good pip and retry\n  Puppet[:pipcmd] = '/usr/bin/pip3'; retry\nend","preventionTips":["Set pipcmd to an absolute path of a real pip (venv or system), never a PATH shim.","Verify `pip --version` prints the standard first line in your node bootstrap.","Upgrade pip on hosts where the banner format is nonstandard (very old or wrapped pips)."],"tags":["puppet","pip","python","packages","version-detection"],"backgroundTag":"version-detection-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}