Skip to main content

Auto-installs missing Python packages at runtime or startup.

Project description

check-install (check_install)

PyPI version Python versions License Downloads

Automatically detect and install missing Python modules at runtime or pre-execution using pip.

📥 Installation

pip install check-install

💡 What It Does

When imported and invoked early in your Python scripts, check_install scans for missing imports:

  • Prompts to install them using pip.
  • Restarts the script seamlessly after installation.
  • Works both during import time and runtime (ModuleNotFoundError).
  • Optionally displays nice output with rich, but works without it.
  • Great for prototyping, scratch scripts, or educational notebooks.

✅ Quick Start

Add this to the very top of your script:

import check_install
check_install.install_hooks_and_preflight()

That’s it! If any module is missing, you’ll be prompted to install it.


📦 Example

Say your script contains:

import check_install
check_install.install_hooks_and_preflight()
import numpy
import yaml

And you don't have numpy or PyYAML installed — you’ll see an interactive prompt:

Missing Dependencies Detected
Import name     PyPI package
──────────────  ─────────────
numpy           numpy
yaml            PyYAML

Attempt to auto-install missing 2 package(s) now? [Y/n]:

It will install and re-execute the script.


🧠 How It Works

  • Uses ast to statically analyze the current script and extract imports.
  • Catches ModuleNotFoundError at runtime using a custom sys.excepthook.
  • Attempts installation via subprocess.run([python -m pip install ...]).
  • Tracks attempted installations to avoid loops.

⚠️ Notes

  • Meant for dev/test scripts — not production!
  • Respects existing venvs, shows interpreter context.
  • Maps known import names to their PyPI equivalents (PILpillow, etc).
  • Requires no external config, arguments, or setup.

🔒 Security & Safety

  • Does not use eval, exec, or shell calls.
  • Uses subprocess securely to invoke pip.
  • Gracefully exits or restarts using os.execv.

🚫 Limitations

  • Won’t resolve C/C++ build errors or OS-level dependencies.
  • Assumes pip is functional and available in the current Python environment.

🧪 Want Tests?

Let me know and I’ll whip up a test suite for you! 🧪


📜 License

MIT License — see the LICENSE file for full text.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

check_install-0.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

check_install-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file check_install-0.1.0.tar.gz.

File metadata

  • Download URL: check_install-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for check_install-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0d1274b7fd6ac6cac6f2b085073d961bf2672e76011fd5cc57c8094112600e06
MD5 3fda85f6caf59424c79d98bdbb246c03
BLAKE2b-256 8703811d9cde7ca0baf9d37a6bdd48d358abdcd482eabb718cc17b0b05567b1f

See more details on using hashes here.

File details

Details for the file check_install-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: check_install-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for check_install-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c97462f71f8a81a0ac4ff8e0b96984a8a3fd87028890601d0e3d93284340287
MD5 c6e67dd8cfeecf29088e8b3ef3152f68
BLAKE2b-256 cca9ce799c347342365d4990d5c4ab54bea6c247f2eff849e33b9848002e3ea2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page