Skip to content

Using toolsツールの使用

Many Python packages provide applications that can be used as tools. uv has specialized support for easily invoking and installing tools.多くの Python パッケージは、ツールとして使用できるアプリケーションを提供します。uv は、ツールを簡単に呼び出してインストールするための専門的なサポートを提供しています。

Running toolsツールの実行

The uvx command invokes a tool without installing it.uvx コマンドは、ツールをインストールせずに呼び出します。

For example, to run ruff:例えば、ruffを実行するには:

$ uvx ruff

Note注意

This is exactly equivalent to:これは正確に次のように等価です:

$ uv tool run ruff

uvx is provided as an alias for convenience.uvx は便利さのためにエイリアスとして提供されています。

Arguments can be provided after the tool name:ツール名の後に引数を指定できます:

$ uvx pycowsay hello from uv

  -------------
< hello from uv >
  -------------
   \   ^__^
    \  (oo)\_______
       (__)\       )\/\
           ||----w |
           ||     ||

Tools are installed into temporary, isolated environments when using uvx.uvx を使用すると、ツールは一時的で隔離された環境にインストールされます。

Note注意

If you are running a tool in a project and the tool requires that your project is installed, e.g., when using pytest or mypy, you'll want to use uv run instead of uvx. Otherwise, the tool will be run in a virtual environment that is isolated from your project.プロジェクト でツールを実行していて、そのツールがプロジェクトのインストールを必要とする場合、例えば、pytestmypy を使用する際には、uv run を使用することをお勧めします。そうしないと、ツールはプロジェクトから隔離された仮想環境で実行されます。

If your project has a flat structure, e.g., instead of using a src directory for modules, the project itself does not need to be installed and uvx is fine. In this case, using uv run is only beneficial if you want to pin the version of the tool in the project's dependencies.プロジェクトがフラットな構造を持っている場合、例えば、モジュール用に src ディレクトリを使用する代わりに、プロジェクト自体をインストールする必要はなく、uvx で問題ありません。この場合、プロジェクトの依存関係でツールのバージョンを固定したい場合にのみ、uv run を使用することが有益です。

Commands with different package names異なるパッケージ名のコマンド

When uvx ruff is invoked, uv installs the ruff package which provides the ruff command. However, sometimes the package and command names differ.コマンド uvx ruff が呼び出されると、uv は ruff コマンドを提供する ruff パッケージをインストールします。しかし、時にはパッケージ名とコマンド名が異なることがあります。

The --from option can be used to invoke a command from a specific package, e.g., http which is provided by httpie:--from オプションを使用して、特定のパッケージからコマンドを呼び出すことができます。例えば、httphttpie によって提供されます:

$ uvx --from httpie http

Requesting specific versions特定のバージョンのリクエスト

To run a tool at a specific version, use command@<version>:特定のバージョンでツールを実行するには、command@<version> を使用します:

$ uvx ruff@0.3.0 check

To run a tool at the latest version, use command@latest:最新バージョンでツールを実行するには、command@latest を使用します:

$ uvx ruff@latest check

The --from option can also be used to specify package versions, as above:--from オプションは、上記のようにパッケージのバージョンを指定するためにも使用できます:

$ uvx --from 'ruff==0.3.0' ruff check

Or, to constrain to a range of versions:また、バージョンの範囲を制限することもできます:

$ uvx --from 'ruff>0.2.0,<0.3.0' ruff check

Note the @ syntax cannot be used for anything other than an exact version.@ 構文は、正確なバージョン以外には使用できないことに注意してください。

Requesting extrasエクストラのリクエスト

The --from option can be used to run a tool with extras:--from オプションを使用して、エクストラ付きでツールを実行することができます:

$ uvx --from 'mypy[faster-cache,reports]' mypy --xml-report mypy_report

This can also be combined with version selection:これはバージョン選択と組み合わせることもできます:

$ uvx --from 'mypy[faster-cache,reports]==1.13.0' mypy --xml-report mypy_report

Requesting different sources異なるソースのリクエスト

The --from option can also be used to install from alternative sources.--from オプションを使用して、代替ソースからインストールすることもできます。

For example, to pull from git:例えば、gitからプルするには:

$ uvx --from git+https://github.com/httpie/cli httpie

You can also pull the latest commit from a specific named branch:特定の名前付きブランチから最新のコミットをプルすることもできます:

$ uvx --from git+https://github.com/httpie/cli@master httpie

Or pull a specific tag:特定のタグをプルすることもできます:

$ uvx --from git+https://github.com/httpie/cli@3.2.4 httpie

Or even a specific commit:あるいは特定のコミットをプルすることもできます:

$ uvx --from git+https://github.com/httpie/cli@2843b87 httpie

Commands with pluginsプラグインを使用したコマンド

Additional dependencies can be included, e.g., to include mkdocs-material when running mkdocs:追加の依存関係を含めることができます。例えば、mkdocsを実行する際にmkdocs-materialを含める場合:

$ uvx --with mkdocs-material mkdocs --help

Installing toolsツールのインストール

If a tool is used often, it is useful to install it to a persistent environment and add it to the PATH instead of invoking uvx repeatedly.ツールを頻繁に使用する場合は、ツールを永続的な環境にインストールし、PATHに追加することが便利です。これにより、uvxを繰り返し呼び出す必要がなくなります。

Tipヒント

uvx is a convenient alias for uv tool run. All of the other commands for interacting with tools require the full uv tool prefix.uvxは、uv tool runの便利なエイリアスです。他のツールとの対話に必要なすべてのコマンドは、完全なuv toolプレフィックスを必要とします。

To install ruff:ruffをインストールするには:

$ uv tool install ruff

When a tool is installed, its executables are placed in a bin directory in the PATH which allows the tool to be run without uv. If it's not on the PATH, a warning will be displayed and uv tool update-shell can be used to add it to the PATH.ツールがインストールされると、その実行可能ファイルはPATH内のbinディレクトリに配置され、uvなしでツールを実行できるようになります。PATHにない場合は警告が表示され、uv tool update-shellを使用してPATHに追加できます。

After installing ruff, it should be available:ruffをインストールした後は、次のように利用可能であるべきです:

$ ruff --version

Unlike uv pip install, installing a tool does not make its modules available in the current environment. For example, the following command will fail:uv pip installとは異なり、ツールをインストールしても、そのモジュールは現在の環境で利用可能にはなりません。たとえば、次のコマンドは失敗します:

$ python -c "import ruff"

This isolation is important for reducing interactions and conflicts between dependencies of tools, scripts, and projects.この分離は、ツール、スクリプト、およびプロジェクトの依存関係間の相互作用や競合を減らすために重要です。

Unlike uvx, uv tool install operates on a package and will install all executables provided by the tool.uvxとは異なり、uv tool installパッケージに対して操作を行い、ツールが提供するすべての実行可能ファイルをインストールします。

For example, the following will install the http, https, and httpie executables:たとえば、次のコマンドはhttphttps、およびhttpieの実行可能ファイルをインストールします:

$ uv tool install httpie

Additionally, package versions can be included without --from:さらに、--fromなしでパッケージのバージョンを含めることができます:

$ uv tool install 'httpie>0.1.0'

And, similarly, for package sources:同様に、パッケージソースについても:

$ uv tool install git+https://github.com/httpie/cli

As with uvx, installations can include additional packages:uvxと同様に、インストールには追加のパッケージを含めることができます:

$ uv tool install mkdocs --with mkdocs-material

Multiple related executables can be installed together in the same tool environment, using the --with-executables-from flag. For example, the following will install the executables from ansible, plus those ones provided by ansible-core and ansible-lint:関連する複数の実行可能ファイルを同じツール環境にインストールするには、--with-executables-fromフラグを使用します。例えば、以下のコマンドは、ansibleからの実行可能ファイルと、ansible-coreおよびansible-lintによって提供される実行可能ファイルをインストールします:

$ uv tool install --with-executables-from ansible-core,ansible-lint ansible

Upgrading toolsツールのアップグレード

To upgrade a tool, use uv tool upgrade:ツールをアップグレードするには、uv tool upgradeを使用します:

$ uv tool upgrade ruff

Tool upgrades will respect the version constraints provided when installing the tool. For example, uv tool install ruff >=0.3,<0.4 followed by uv tool upgrade ruff will upgrade Ruff to the latest version in the range >=0.3,<0.4.ツールのアップグレードは、ツールをインストールする際に提供されたバージョン制約を尊重します。例えば、uv tool install ruff >=0.3,<0.4の後にuv tool upgrade ruffを実行すると、Ruffは範囲>=0.3,<0.4内の最新バージョンにアップグレードされます。

To instead replace the version constraints, re-install the tool with uv tool install:代わりにバージョン制約を置き換えるには、uv tool installでツールを再インストールします:

$ uv tool install ruff>=0.4

To instead upgrade all tools:代わりにすべてのツールをアップグレードするには:

$ uv tool upgrade --all

Requesting Python versionsPythonバージョンのリクエスト

By default, uv will use your default Python interpreter (the first it finds) when running, installing, or upgrading tools. You can specify the Python interpreter to use with the --python option.デフォルトでは、uvはツールを実行、インストール、またはアップグレードする際に、デフォルトのPythonインタープリター(最初に見つかったもの)を使用します。使用するPythonインタープリターを指定するには、--pythonオプションを使用します。

For example, to request a specific Python version when running a tool:例えば、ツールを実行する際に特定のPythonバージョンをリクエストするには:

$ uvx --python 3.10 ruff

Or, when installing a tool:また、ツールをインストールする際には:

$ uv tool install --python 3.10 ruff

Or, when upgrading a tool:また、ツールをアップグレードする際には:

$ uv tool upgrade --python 3.10 ruff

For more details on requesting Python versions, see the Python version concept page.Pythonバージョンのリクエストに関する詳細は、 Pythonバージョンの概念ページを参照してください。

Legacy Windows ScriptsレガシーWindowsスクリプト

Tools also support running legacy setuptools scripts. These scripts are available via $(uv tool dir)\<tool-name>\Scripts when installed.ツールはまた、 レガシーsetuptoolsスクリプトの実行をサポートしています。 これらのスクリプトは、インストール時に $(uv tool dir)\<tool-name>\Scripts から利用可能です。

Currently only legacy scripts with the .ps1, .cmd, and .bat extensions are supported.現在、.ps1.cmd、および.bat拡張子を持つレガシースクリプトのみがサポートされています。

For example, below is an example running a Command Prompt script.例えば、以下はコマンドプロンプトスクリプトを実行する例です。

$ uv tool run --from nuitka==2.6.7 nuitka.cmd --version

In addition, you don't need to specify the extension. uvx will automatically look for files ending in .ps1, .cmd, and .bat in that order of execution on your behalf.さらに、拡張子を指定する必要はありません。 uvx は、自動的に .ps1.cmd、および .bat で終わるファイルを、その実行順序で探します。

$ uv tool run --from nuitka==2.6.7 nuitka --version

Next steps次のステップ

To learn more about managing tools with uv, see the Tools concept page and the command reference.uvを使用したツールの管理について詳しく知るには、ツールの概念ページと、 コマンドリファレンスを参照してください。

Or, read on to learn how to work on projects.または、プロジェクトに取り組む方法を学ぶために読み進めてください。