{"id":24084105,"url":"https://github.com/tos-kamiya/commandnotfound","last_synced_at":"2026-06-14T15:36:19.065Z","repository":{"id":39892789,"uuid":"507260842","full_name":"tos-kamiya/commandnotfound","owner":"tos-kamiya","description":"A wrapper of command-not-found command for subprocess.run","archived":false,"fork":false,"pushed_at":"2022-06-27T16:10:29.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-10T00:19:23.802Z","etag":null,"topics":["command-not-found","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tos-kamiya.png","metadata":{"files":{"readme":"README-pypi.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-25T08:51:44.000Z","updated_at":"2022-06-25T13:32:00.000Z","dependencies_parsed_at":"2022-08-30T19:02:31.833Z","dependency_job_id":null,"html_url":"https://github.com/tos-kamiya/commandnotfound","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tos-kamiya%2Fcommandnotfound","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tos-kamiya%2Fcommandnotfound/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tos-kamiya%2Fcommandnotfound/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tos-kamiya%2Fcommandnotfound/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tos-kamiya","download_url":"https://codeload.github.com/tos-kamiya/commandnotfound/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240962362,"owners_count":19885472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-not-found","python3"],"created_at":"2025-01-10T00:19:25.037Z","updated_at":"2026-06-14T15:36:19.013Z","avatar_url":"https://github.com/tos-kamiya.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# commandnotfound\n\nThis package provides a wrapper of command-not-found commands:\n\n* Apt-based distribution's `/usr/lib/command-not-found`\n* Dnf-based distribution's `/usr/libexec/pk-command-not-found`\n\nYou know that when you type a command and then try to run it, if the command is not found, you will be informed that there is a command with a similar name, or you will be prompted to install the package required by it.\n\nI want my Python scripts that call such commands internally to also display this kind of friendly messages. However, the trick does not work when you try to run a command in `subprocess.run`. It simply displays a \"command not found\" message.\n\nThe `commandnotfound` wraps `subprocess.run`, and when the command passed as its argument is not found, it invoke the command-not-found commands.\n\n**Tested on Ubuntu and Fedora.**\n\n## How it works\n\nIn some apt-based distributions such as Ubuntu, shows a hint as an error message, when a user types wrong command name, e.g.:\n\n```sh\n$ converT\n\nCommand 'converT' not found, did you mean:\n\n  command 'convert' from deb imagemagick-6.q16 (8:6.9.10.23+dfsg-2.1ubuntu11.4)\n....\n```\n\nThis help system is implemented as `/usr/lib/command-not-found`, and the bash call it when a command is not found on PATH directories.\n\nThe help system does not work when you run command in a Python code with `subprocess.run`, e.g.:\n\n```sh\n$ python3\nPython 3.8.10 (default, Mar 15 2022, 12:22:08) \n[GCC 9.4.0] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\u003e\u003e\u003e import subprocess \n\u003e\u003e\u003e subprocess.run([\"converT\"])\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n....\nFileNotFoundError: [Errno 2] No such file or directory: 'converT'\n\u003e\u003e\u003e \n```\n\nIn short, the error message says that the command could not be found.\n\nSo the commandnotfound wrapper wraps `subprocess.run` and detects `FileNotFoundError` is thrown or not, and in case it thrown, call the help command `/usr/lib/command-not-found`.\n\n```sh\n$ python3 \nPython 3.8.10 (default, Mar 15 2022, 12:22:08) \n[GCC 9.4.0] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\u003e\u003e\u003e import subprocess\n\u003e\u003e\u003e import commandnotfound\n\u003e\u003e\u003e wrapped_run = commandnotfound.wrap(subprocess.run)\n\u003e\u003e\u003e wrapped_run([\"converT\"])\n\nCommand 'converT' not found, did you mean:\n\n  command 'convert' from deb imagemagick-6.q16 (8:6.9.10.23+dfsg-2.1ubuntu11.4)\n....\nFileNotFoundError: [Errno 2] No such file or directory: 'converT'\n\u003e\u003e\u003e\n```\n\nThis time, the error message pointed out that the command name may be wrong!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftos-kamiya%2Fcommandnotfound","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftos-kamiya%2Fcommandnotfound","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftos-kamiya%2Fcommandnotfound/lists"}