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")、呼び出し元の try で受け止める書き方(IPython など)では入れない
  • Jupyter / IPython でもそのまま動く

スクリプトに書いておく

# /// 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 ... pip install と同じ書き方: -r requirements.txt(-r入れ子・-c・--hash・-i)/ -e . / -U / --no-deps / --force-reinstall / --dry-run / -t DIR / --user
autopip uninstall pkg... 消す(-r ファイル も可)
autopip list [--outdated] / show pkg 入っているもの / 新しい版が出ているもの / 詳細
autopip upgrade pkg... / --all まとめて最新に(--dry-run で見るだけ)
autopip freeze 環境全体を pip freeze 形式で
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.4.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.4.0
File Size Uploaded
pip_auto-0.4.0.tar.gz 66.4 kB Details

Built distribution (wheel)

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

Total release size: 126.3 kB

Release files / pip_auto-0.4.0.tar.gz

Download URL pip_auto-0.4.0.tar.gz
Size 66.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d13a0424e6a694391feec44271d81876afce1c15870d816487201f2b3793a479
BLAKE2b-256 checksum
How to use checksums
3b513126b5d1cee7de8c830a7ba504f9117f13f50e2ab86b68465dab7eaa6fc4
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.4.0-py3-none-any.whl

Download URL pip_auto-0.4.0-py3-none-any.whl
Size 59.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05d235750e03dbb868d4a893a7786d8c642b657450b56a9e7a860458334be12c
BLAKE2b-256 checksum
How to use checksums
8d0bcd2815f42f79e466134501d832e51a978c9a590c4013b013617c975be256
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

This release

0.4.0 This release

2 release files

0.3.0

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