Skip to content

FileNotFoundError when upgrading model-checker: 'pip' command not found #74

@benbrastmckie

Description

@benbrastmckie

Bug Description

The model-checker -u upgrade command fails with a FileNotFoundError because it tries to call pip directly, which doesn't exist on many systems where only pip3 is available.

Environment

  • OS: macOS (Darwin 24.6.0)
  • Python: 3.13
  • model-checker version: 1.1.0
  • Installation method: pip3 install model-checker

Steps to Reproduce

  1. Install model-checker: pip3 install model-checker
  2. Run: model-checker -u to upgrade

Expected Behavior

The package should upgrade successfully.

Actual Behavior

The upgrade fails with the following error:

◆ Documents ❯❯❯ model-checker -u
Upgrading package
Traceback (most recent call last):
  File "/Users/nicky/Library/Python/3.13/bin/model-checker", line 7, in <module>
    sys.exit(run())
             ~~~^^
  File "/Users/nicky/Library/Python/3.13/lib/python/site-packages/model_checker/__main__.py", line 266, in run
    main()
    ~~~~^^
  File "/Users/nicky/Library/Python/3.13/lib/python/site-packages/model_checker/__main__.py", line 244, in main
    subprocess.run(['pip', 'install', '--upgrade', package_name], check=True)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/subprocess.py", line 554, in run
    with Popen(*popenargs, **kwargs) as process:
         ~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/subprocess.py", line 1039, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        pass_fds, cwd, env,
                        ^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
                        gid, gids, uid, umask,
                        ^^^^^^^^^^^^^^^^^^^^^^
                        start_new_session, process_group)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/subprocess.py", line 1972, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'pip'

Root Cause

The issue is in __main__.py line 244 which hardcodes 'pip' in the subprocess call:

subprocess.run(['pip', 'install', '--upgrade', package_name], check=True)

On many systems (especially macOS with Homebrew Python), only pip3 exists in the PATH, not pip.

Suggested Fix

The code should use one of these approaches:

  1. Use sys.executable -m pip instead of calling pip directly:
    subprocess.run([sys.executable, '-m', 'pip', 'install', '--upgrade', package_name], check=True)
  2. Try pip first, fall back to pip3 if not found
  3. Use shutil.which() to find the available pip command

Option 1 is the most reliable as it ensures using the same Python interpreter that's running the script.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions