Skip to main content

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 (PIL → pillow, 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.

Metadata

Release files for check-install 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for check-install 0.1.1
File Size Uploaded Provenance Actions
check_install-0.1.1.tar.gz 6.8 kB Without provenance Details for check_install-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for check-install 0.1.1
File Interpreter ABI Platform Actions
check_install-0.1.1-py3-none-any.whl Python 3 none any Details for check_install-0.1.1-py3-none-any.whl

Total release size: 14.1 kB

Release files / check_install-0.1.1.tar.gz

Download URL check_install-0.1.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ba6a7d99288602cf9f6cf6cf28b109feca93a66404e4ac6d282e24997d6dfa27
BLAKE2b-256 checksum
How to use checksums
3ae6095e202eff6a2f83102a934c1e0e897fd2d9348d6a1a56f9d4c60377f34f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / check_install-0.1.1-py3-none-any.whl

Download URL check_install-0.1.1-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a35777fb25b8b3a0b2dfc62b0e1ea09dc44111bebc61f07fafe43f499fc62dd0
BLAKE2b-256 checksum
How to use checksums
854f0c85de07b90de314e1697e97b7c479b94b61dd57f35b4fc848bc2ddbbd2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for check-install 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page