Skip to main content

pip-auto

import するだけ。無いモジュールは勝手に入る。

pip install pip-auto

これだけ。あとは普通に Python を書いて動かすと、足りないモジュールがその場で PyPI から入ってそのまま動き続けます。

import pyfiglet             # 入ってなくても OK
from PIL import Image       # import 名と pip 名が違っても OK(pillow を入れる)
import cv2                  # opencv-python を入れる
print(pyfiglet.figlet_format("hello"))
[autopip] 'pyfiglet' が無い → pyfiglet を入れる
[autopip] pyfiglet==1.0.4 入った (2.51s)

何が便利か

  • 入れるだけで有効: pip install pip-auto で ON。pip uninstall pip-auto で完全に元通り
  • 名前を当てる: PIL→pillow、cv2→opencv-python、google.generativeai→google-generativeai など。 候補は wheel の中身まで確認してから入れる(同名の別物は入れない)
  • 速い: pip を使わない自前インストーラ。依存を並列で先読みして解決し、全ファイルを 1 回でまとめて展開。 2 回目以降はキャッシュからハードリンクを張るだけ(pip の 5〜10 倍程度)。Python の起動への上乗せは約 5ms
  • 安全: 人気パッケージにそっくりな名前(タイポスクワット)や、公開されたばかりの無名パッケージは自動では入れない。 失敗したら途中まで入ったものも含めて全部元に戻す
  • ライブラリの「無くても動く」import は無視: try: import x except ImportError: や importlib.util.find_spec("x") では入れない

スクリプトに書いておく

# /// script
# dependencies = ["requests<3", "rich"]
# ///
import requests, rich          # PEP 723 ブロックがあれば最初にまとめて入れる
import numpy  # autopip: numpy<2   ← 行末コメントでバージョン指定

コマンド

コマンド 内容
autopip run x.py 足りないものを先にまとめて入れてから実行(--venv で隣に .venv を作ってそこで)
autopip lock x.py 全部のバージョンと sha256 を固定した x.autopip.lock を作る。以後 run はその通りに入れる
autopip freeze x.py --requirements / --pep723 使っているものを書き出す
autopip install pkg... / uninstall pkg... 自前インストーラで入れる / 消す
autopip clean [--days 30] [--yes] しばらく使ってない自動インストール品を掃除
autopip gui ブラウザで一覧・掃除・設定(127.0.0.1 のみ)
autopip check pkg 安全チェックだけ
autopip config ask true 入れる前に毎回確認する
autopip off / on 一時的に止める / 戻す

環境変数 AUTOPIP_DISABLE=1 でその場だけ無効にできます。

設定 (autopip config キー 値)

  • ask … true で入れる前に確認(端末から直接聞く。答えられない環境では入れない)
  • safety … strict(既定)/ warn / off
  • link_mode … hardlink(既定・速い)/ copy(環境ごとに別ファイル)
  • index_url / extra_index_urls … PyPI 以外のインデックス(pip.ini / PIP_INDEX_URL も読みます)

注意

  • 自動で入れるのは PyPI 上のパッケージです。何を入れたかは毎回ログに出ます
  • ハードリンクモードでは同じファイルを複数の環境で共有します。入れたファイルを直接書き換える使い方をするなら link_mode copy に
  • Python 3.10 以上。Windows で主に確認しています(Linux / macOS の wheel 選びは packaging に任せています)

English

Just import it — missing modules are installed from PyPI on the fly. pip install pip-auto enables it for that Python (a .pth hook); pip uninstall pip-auto removes it completely. It maps import names to distribution names (PIL→pillow, cv2→opencv-python), verifies the wheel really contains the module, blocks typosquats / brand-new unknown packages, resolves with backtracking, and installs everything in one parallel batch with hard links from a local cache. Library-internal optional imports are left alone. Supports PEP 723 script metadata, lock files with sha256, autopip gui, autopip clean, and autopip freeze.

Metadata

Release files for pip-auto 0.3.0

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

Source distribution (sdist)

Source distribution for pip-auto 0.3.0
File Size Uploaded
pip_auto-0.3.0.tar.gz 59.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pip-auto 0.3.0
File Interpreter ABI Platform
pip_auto-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 113.8 kB

Release files / pip_auto-0.3.0.tar.gz

Download URL pip_auto-0.3.0.tar.gz
Size 59.1 kB
Tags Source
SHA-256 checksum
How to use checksums
792cbf4f64aa2993b9a3c0e7da2dd602a662041d76f54d3cd16ad0255715c6e7
BLAKE2b-256 checksum
How to use checksums
87d0560fcef31ad94389b5b243f5a0011e4e999463618ddb110711c2d8d22e12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.5

Release files / pip_auto-0.3.0-py3-none-any.whl

Download URL pip_auto-0.3.0-py3-none-any.whl
Size 54.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa17c98ab2a286db625676e9c7c58b6796dfebae46cc6fbc4548b7df1c636e04
BLAKE2b-256 checksum
How to use checksums
e2c5ce8352666056fd9d6cf46541789c11f9e6c6897770888f3f3cc96d2707e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.5

Release history Release notifications | RSS feed

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

This release

0.3.0 This release

2 release files

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