Managing dependencies依存関係の管理
Dependency fields依存関係フィールド
Dependencies of the project are defined in several fields:プロジェクトの依存関係は、いくつかのフィールドで定義されています:
project.dependencies: Published dependencies.project.dependencies: 公開された依存関係。project.optional-dependencies: Published optional dependencies, or "extras".project.optional-dependencies: 公開されたオプションの依存関係、または「extras」。dependency-groups: Local dependencies for development.dependency-groups: 開発用のローカル依存関係。tool.uv.sources: Alternative sources for dependencies during development.tool.uv.sources: 開発中の依存関係のための代替ソース。
Note注意
The project.dependencies and project.optional-dependencies fields can be used even if
project isn't going to be published. dependency-groups are a recently standardized feature
and may not be supported by all tools yet.project.dependencies および project.optional-dependencies フィールドは、プロジェクトが公開されない場合でも使用できます。dependency-groups は最近標準化された機能であり、すべてのツールでサポートされているわけではありません。
uv supports modifying the project's dependencies with uv add and uv remove, but dependency
metadata can also be updated by editing the pyproject.toml directly.uvは、uv add および uv remove を使用してプロジェクトの依存関係を変更することをサポートしていますが、依存関係のメタデータは pyproject.toml を直接編集することでも更新できます。
Adding dependencies依存関係の追加
To add a dependency:依存関係を追加するには:
An entry will be added in the project.dependencies field:project.dependencies フィールドにエントリが追加されます:
The --dev, --group, or
--optional flags can be used to add dependencies to an alternative
field.--dev, --group, または
--optional フラグを使用して、代替フィールドに依存関係を追加できます。
The dependency will include a constraint, e.g., >=0.27.2, for the most recent, compatible version
of the package. The kind of bound can be adjusted with
--bounds, or the constraint can be provided directly:依存関係には制約が含まれます。例えば、パッケージの最新の互換バージョンに対して >=0.27.2 のような制約です。境界の種類は
--bounds で調整できます。または、制約を直接提供することもできます:
When adding a dependency from a source other than a package registry, uv will add an entry in the
sources field. For example, when adding httpx from GitHub:パッケージレジストリ以外のソースから依存関係を追加する場合、uv は
sources フィールドにエントリを追加します。例えば、GitHub から httpx を追加する場合:
The pyproject.toml will include a Git source entry:pyproject.toml には Git ソースエントリ が含まれます:
[project]
name = "example"
version = "0.1.0"
dependencies = [
"httpx",
]
[tool.uv.sources]
httpx = { git = "https://github.com/encode/httpx" }
If a dependency cannot be used, uv will display an error.:依存関係が使用できない場合、uv はエラーを表示します。
$ uv add "httpx>9999"
× No solution found when resolving dependencies:
╰─▶ Because only httpx<=1.0.0b0 is available and your project depends on httpx>9999,
we can conclude that your project's requirements are unsatisfiable.
Importing dependencies from requirements filesrequirements ファイルからの依存関係のインポート
Dependencies declared in a requirements.txt file can be added to the project with the -r option:requirements.txt ファイルに宣言された依存関係は、-r オプションを使用してプロジェクトに追加できます:
See the pip migration guide for more details.pip 移行ガイドを参照して、詳細を確認してください。
Removing dependencies依存関係の削除
To remove a dependency:依存関係を削除するには:
The --dev, --group, or --optional flags can be used to remove a dependency from a specific
table.--dev、--group、または--optionalフラグを使用して、特定のテーブルから依存関係を削除できます。
If a source is defined for the removed dependency, and there are no other references to the dependency, it will also be removed.削除された依存関係に対してソースが定義されている場合、他にその依存関係への参照がなければ、それも削除されます。
Changing dependencies依存関係の変更
To change an existing dependency, e.g., to use a different constraint for httpx:既存の依存関係を変更するには、例えばhttpxの異なる制約を使用する場合:
Note注意
In this example, we are changing the constraints for the dependency in the pyproject.toml.
The locked version of the dependency will only change if necessary to satisfy the new
constraints. To force the package version to update to the latest within the constraints, use --upgrade-package <name>, e.g.:この例では、pyproject.toml内の依存関係の制約を変更しています。依存関係のロックされたバージョンは、新しい制約を満たすために必要な場合にのみ変更されます。制約内で最新のパッケージバージョンに更新するには、--upgrade-package <name>を使用します。例えば:
See the lockfile documentation for more details on upgrading packages.パッケージのアップグレードに関する詳細は、ロックファイルのドキュメントを参照してください。
Requesting a different dependency source will update the tool.uv.sources table, e.g., to use
httpx from a local path during development:異なる依存関係ソースを要求すると、tool.uv.sourcesテーブルが更新されます。例えば、開発中にローカルパスからhttpxを使用するには:
Platform-specific dependenciesプラットフォーム固有の依存関係
To ensure that a dependency is only installed on a specific platform or on specific Python versions, use environment markers.特定のプラットフォームまたは特定のPythonバージョンでのみ依存関係がインストールされるようにするには、環境マーカーを使用してください。
For example, to install jax on Linux, but not on Windows or macOS:例えば、Linuxにjaxをインストールするが、WindowsやmacOSにはインストールしない場合:
The resulting pyproject.toml will then include the environment marker in the dependency
definition:結果として得られるpyproject.tomlには、依存関係の定義に環境マーカーが含まれます:
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = ["jax; sys_platform == 'linux'"]
Similarly, to include numpy on Python 3.11 and later:同様に、Python 3.11以降でnumpyを含めるには:
See Python's environment marker documentation for a complete enumeration of the available markers and operators.利用可能なマーカーと演算子の完全な列挙については、Pythonの環境マーカードキュメントを参照してください。
Tipヒント
Dependency sources can also be changed per-platform.依存関係のソースは、プラットフォームごとに変更することもできます。
Project dependenciesプロジェクトの依存関係
The project.dependencies table represents the dependencies that are used when uploading to PyPI or
building a wheel. Individual dependencies are specified using
dependency specifiers
syntax, and the table follows the
PEP 621 standard.project.dependenciesテーブルは、PyPIにアップロードする際やホイールをビルドする際に使用される依存関係を表します。個々の依存関係は、依存関係指定子構文を使用して指定され、テーブルはPEP 621標準に従います。
project.dependencies defines the list of packages that are required for the project, along with
the version constraints that should be used when installing them. Each entry includes a dependency
name and version. An entry may include extras or environment markers for platform-specific packages.
For example:project.dependenciesは、プロジェクトに必要なパッケージのリストを定義し、それらをインストールする際に使用すべきバージョン制約を含みます。各エントリには依存関係の名前とバージョンが含まれます。エントリには、プラットフォーム固有のパッケージのためのextrasや環境マーカーを含めることができます。例えば:
[project]
name = "albatross"
version = "0.1.0"
dependencies = [
# Any version in this range
"tqdm >=4.66.2,<5",
# Exactly this version of torch
"torch ==2.2.2",
# Install transformers with the torch extra
"transformers[torch] >=4.39.3,<5",
# Only install this package on older python versions
# See "Environment Markers" for more information
"importlib_metadata >=7.1.0,<8; python_version < '3.10'",
"mollymawk ==0.1.0"
]
Dependency sources依存関係のソース
The tool.uv.sources table extends the standard dependency tables with alternative dependency
sources, which are used during development.tool.uv.sourcesテーブルは、開発中に使用される代替依存関係ソースで標準の依存関係テーブルを拡張します。
Dependency sources add support for common patterns that are not supported by the
project.dependencies standard, like editable installations and relative paths. For example, to
install foo from a directory relative to the project root:依存関係ソースは、project.dependencies 標準ではサポートされていない、編集可能なインストールや相対パスなどの一般的なパターンをサポートします。例えば、プロジェクトルートに対して相対的なディレクトリから foo をインストールするには:
[project]
name = "example"
version = "0.1.0"
dependencies = ["foo"]
[tool.uv.sources]
foo = { path = "./packages/foo" }
The following dependency sources are supported by uv:uv によってサポートされている依存関係ソースは次のとおりです:
- Index: A package resolved from a specific package index.インデックス: 特定のパッケージインデックスから解決されたパッケージ。
- Git: A Git repository.Git: Git リポジトリ。
- URL: A remote wheel or source distribution.URL: リモートホイールまたはソース配布。
- Path: A local wheel, source distribution, or project directory.パス: ローカルホイール、ソース配布、またはプロジェクトディレクトリ。
- Workspace: A member of the current workspace.ワークスペース: 現在のワークスペースのメンバー。
Important重要
Sources are only respected by uv. If another tool is used, only the definitions in the standard project tables will be used. If another tool is being used for development, any metadata provided in the source table will need to be re-specified in the other tool's format.ソースは uv によってのみ尊重されます。他のツールが使用されている場合、標準プロジェクトテーブルの定義のみが使用されます。開発に別のツールが使用されている場合、ソーステーブルで提供されたメタデータは、他のツールの形式で再指定する必要があります。
Indexインデックス
To add Python package from a specific index, use the --index option:特定のインデックスから Python パッケージを追加するには、--index オプションを使用します:
uv will store the index in [[tool.uv.index]] and add a [tool.uv.sources] entry:uvはインデックスを[[tool.uv.index]]に保存し、[tool.uv.sources]エントリを追加します。
[project]
dependencies = ["torch"]
[tool.uv.sources]
torch = { index = "pytorch" }
[[tool.uv.index]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cpu"
Tipヒント
The above example will only work on x86-64 Linux, due to the specifics of the PyTorch index. See the PyTorch guide for more information about setting up PyTorch.上記の例は、PyTorchインデックスの特性により、x86-64 Linuxでのみ機能します。 詳細な設定については、PyTorchガイドを参照してください。
Using an index source pins a package to the given index — it will not be downloaded from other
indexes.indexソースを使用すると、パッケージが指定されたインデックスに固定され、他のインデックスからはダウンロードされません。
When defining an index, an explicit flag can be included to indicate that the index should only
be used for packages that explicitly specify it in tool.uv.sources. If explicit is not set,
other packages may be resolved from the index, if not found elsewhere.インデックスを定義する際に、explicitフラグを含めることで、そのインデックスがのみ指定されたパッケージに使用されるべきであることを示すことができます。explicitが設定されていない場合、他のパッケージは、他の場所で見つからない場合にインデックスから解決される可能性があります。
[[tool.uv.index]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cpu"
explicit = true
GitGit
To add a Git dependency source, prefix a Git-compatible URL with git+.Git依存関係ソースを追加するには、Git互換のURLの前にgit+を付けます。
For example:例えば:
$ # Install over HTTP(S).
$ uv add git+https://github.com/encode/httpx
$ # Install over SSH.
$ uv add git+ssh://git@github.com/encode/httpx
[project]
dependencies = ["httpx"]
[tool.uv.sources]
httpx = { git = "https://github.com/encode/httpx" }
Specific Git references can be requested, e.g., a tag:特定のGitリファレンスを要求することができます。例えば、タグ:
[project]
dependencies = ["httpx"]
[tool.uv.sources]
httpx = { git = "https://github.com/encode/httpx", tag = "0.27.0" }
Or, a branch:または、ブランチ:
[project]
dependencies = ["httpx"]
[tool.uv.sources]
httpx = { git = "https://github.com/encode/httpx", branch = "main" }
Or, a revision (commit):または、リビジョン(コミット):
[project]
dependencies = ["httpx"]
[tool.uv.sources]
httpx = { git = "https://github.com/encode/httpx", rev = "326b9431c761e1ef1e00b9f760d1f654c8db48c6" }
A subdirectory may be specified if the package isn't in the repository root:パッケージがリポジトリのルートにない場合は、subdirectoryを指定できます:
[project]
dependencies = ["langchain"]
[tool.uv.sources]
langchain = { git = "https://github.com/langchain-ai/langchain", subdirectory = "libs/langchain" }
URLURL
To add a URL source, provide a https:// URL to either a wheel (ending in .whl) or a source
distribution (typically ending in .tar.gz or .zip; see
here for all supported formats).URLソースを追加するには、https://で始まるURLをホイール(.whlで終わる)またはソース配布(通常は.tar.gzまたは.zipで終わる)に提供してください。すべてのサポートされているフォーマットについては、こちらを参照してください。
For example:例えば:
$ uv add "https://files.pythonhosted.org/packages/5c/2d/3da5bdf4408b8b2800061c339f240c1802f2e82d55e50bd39c5a881f47f0/httpx-0.27.0.tar.gz"
Will result in a pyproject.toml with:pyproject.tomlが次のようになります:
[project]
dependencies = ["httpx"]
[tool.uv.sources]
httpx = { url = "https://files.pythonhosted.org/packages/5c/2d/3da5bdf4408b8b2800061c339f240c1802f2e82d55e50bd39c5a881f47f0/httpx-0.27.0.tar.gz" }
URL dependencies can also be manually added or edited in the pyproject.toml with the
{ url = <url> } syntax. A subdirectory may be specified if the source distribution isn't in the
archive root.URL依存関係は、pyproject.tomlに{ url = <url> }構文を使用して手動で追加または編集することもできます。ソース配布がアーカイブのルートにない場合は、subdirectoryを指定できます。
Pathパス
To add a path source, provide the path of a wheel (ending in .whl), a source distribution
(typically ending in .tar.gz or .zip; see
here for all supported formats), or a directory
containing a pyproject.toml.パスソースを追加するには、ホイールのパス(.whlで終わる)、ソース配布(通常は.tar.gzまたは.zipで終わる; すべてのサポートされているフォーマットについてはこちらを参照)またはpyproject.tomlを含むディレクトリのパスを提供してください。
For example:例えば:
Will result in a pyproject.toml with:pyproject.tomlが次のようになります:
[project]
dependencies = ["foo"]
[tool.uv.sources]
foo = { path = "/example/foo-0.1.0-py3-none-any.whl" }
The path may also be a relative path:パスは相対パスでも構いません:
Or, a path to a project directory:または、プロジェクトディレクトリへのパス:
Important重要
When using a directory as a path dependency, uv will attempt to build and install the target as a package by default. See the virtual dependency documentation for details.ディレクトリをパス依存関係として使用する場合、uvはデフォルトでターゲットをパッケージとしてビルドおよびインストールしようとします。詳細については、仮想依存関係のドキュメントを参照してください。
An editable installation is not used for path dependencies by default. An editable installation may be requested for project directories:editable installation はデフォルトではパス依存関係には使用されません。プロジェクトディレクトリに対しては、editable installation を要求することができます:
Which will result in a pyproject.toml with:これにより、pyproject.toml が生成されます:
[project]
dependencies = ["bar"]
[tool.uv.sources]
bar = { path = "../projects/bar", editable = true }
Tipヒント
For multiple packages in the same repository, workspaces may be a better fit.同じリポジトリ内の複数のパッケージの場合、workspaces の方が適しているかもしれません。
Workspace memberWorkspace member
To declare a dependency on a workspace member, add the member name with { workspace = true }. All
workspace members must be explicitly stated. Workspace members are always
editable . See the workspace documentation for more
details on workspaces.ワークスペースメンバーへの依存関係を宣言するには、メンバー名を { workspace = true } と共に追加します。すべてのワークスペースメンバーは明示的に記載する必要があります。ワークスペースメンバーは常にeditableです。ワークスペースに関する詳細はworkspace ドキュメントを参照してください。
[project]
dependencies = ["foo==0.1.0"]
[tool.uv.sources]
foo = { workspace = true }
[tool.uv.workspace]
members = [
"packages/foo"
]
Platform-specific sourcesPlatform-specific sources
You can limit a source to a given platform or Python version by providing dependency specifiers-compatible environment markers for the source.特定のプラットフォームまたはPythonバージョンにソースを制限するには、dependency specifiers-互換の環境マーカーをソースに提供します。
For example, to pull httpx from GitHub, but only on macOS, use the following:例えば、httpx をGitHubから取得するが、macOSのみに限定するには、次のようにします:
[project]
dependencies = ["httpx"]
[tool.uv.sources]
httpx = { git = "https://github.com/encode/httpx", tag = "0.27.2", marker = "sys_platform == 'darwin'" }
By specifying the marker on the source, uv will still include httpx on all platforms, but will
download the source from GitHub on macOS, and fall back to PyPI on all other platforms.ソースにマーカーを指定することで、uvはすべてのプラットフォームでhttpxを含めますが、macOSではGitHubからソースをダウンロードし、他のすべてのプラットフォームではPyPIにフォールバックします。
Multiple sourcesMultiple sources
You can specify multiple sources for a single dependency by providing a list of sources, disambiguated by PEP 508-compatible environment markers.単一の依存関係に対して複数のソースを指定するには、ソースのリストを提供し、PEP 508互換の環境マーカーで区別します。
For example, to pull in different httpx tags on macOS vs. Linux:例えば、macOSとLinuxで異なるhttpxタグを取得するには:
[project]
dependencies = ["httpx"]
[tool.uv.sources]
httpx = [
{ git = "https://github.com/encode/httpx", tag = "0.27.2", marker = "sys_platform == 'darwin'" },
{ git = "https://github.com/encode/httpx", tag = "0.24.1", marker = "sys_platform == 'linux'" },
]
This strategy extends to using different indexes based on environment markers. For example, to
install torch from different PyTorch indexes based on the platform:この戦略は、環境マーカーに基づいて異なるインデックスを使用することにも拡張されます。例えば、プラットフォームに基づいて異なるPyTorchインデックスからtorchをインストールするには:
[project]
dependencies = ["torch"]
[tool.uv.sources]
torch = [
{ index = "torch-cpu", marker = "platform_system == 'Darwin'"},
{ index = "torch-gpu", marker = "platform_system == 'Linux'"},
]
[[tool.uv.index]]
name = "torch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true
[[tool.uv.index]]
name = "torch-gpu"
url = "https://download.pytorch.org/whl/cu124"
explicit = true
Disabling sourcesソースの無効化
To instruct uv to ignore the tool.uv.sources table (e.g., to simulate resolving with the package's
published metadata), use the --no-sources flag:uvにtool.uv.sourcesテーブルを無視させるには(例えば、パッケージの公開メタデータで解決をシミュレートするため)、--no-sourcesフラグを使用します:
The use of --no-sources will also prevent uv from discovering any
workspace members that could satisfy a given dependency.--no-sourcesを使用すると、与えられた依存関係を満たす可能性のあるワークスペースメンバーをuvが発見するのを防ぎます。
Optional dependenciesオプションの依存関係
It is common for projects that are published as libraries to make some features optional to reduce
the default dependency tree. For example, Pandas has an
excel extra and a
plot extra to avoid
installation of Excel parsers and matplotlib unless someone explicitly requires them. Extras are
requested with the package[<extra>] syntax, e.g., pandas[plot, excel].ライブラリとして公開されるプロジェクトでは、デフォルトの依存関係ツリーを減らすために、一部の機能をオプションにすることが一般的です。例えば、Pandasには、Excelパーサーやmatplotlibのインストールを避けるために、誰かが明示的に要求しない限り、excelエクストラとplotエクストラがあります。エクストラはpackage[<extra>]構文で要求されます。例えば、pandas[plot, excel]のように。
Optional dependencies are specified in [project.optional-dependencies], a TOML table that maps
from extra name to its dependencies, following dependency specifiers
syntax.オプションの依存関係は、[project.optional-dependencies]に指定され、エクストラ名からその依存関係へのマッピングを行うTOMLテーブルです。これは依存関係指定子構文に従います。
Optional dependencies can have entries in tool.uv.sources the same as normal dependencies.オプションの依存関係は、通常の依存関係と同様にtool.uv.sourcesにエントリを持つことができます。
[project]
name = "pandas"
version = "1.0.0"
[project.optional-dependencies]
plot = [
"matplotlib>=3.6.3"
]
excel = [
"odfpy>=1.4.1",
"openpyxl>=3.1.0",
"python-calamine>=0.1.7",
"pyxlsb>=1.0.10",
"xlrd>=2.0.1",
"xlsxwriter>=3.0.5"
]
To add an optional dependency, use the --optional <extra> option:オプションの依存関係を追加するには、--optional <extra>オプションを使用します:
Note注意
If you have optional dependencies that conflict with one another, resolution will fail unless you explicitly declare them as conflicting.互いに競合するオプションの依存関係がある場合、明示的に競合として宣言しない限り、解決は失敗します。
Sources can also be declared as applying only to a specific optional dependency. For example, to
pull torch from different PyTorch indexes based on an optional cpu or gpu extra:ソースは特定のオプションの依存関係にのみ適用されるように宣言することもできます。たとえば、オプションのcpuまたはgpuエクストラに基づいて、異なるPyTorchインデックスからtorchを取得するには:
[project]
dependencies = []
[project.optional-dependencies]
cpu = [
"torch",
]
gpu = [
"torch",
]
[tool.uv.sources]
torch = [
{ index = "torch-cpu", extra = "cpu" },
{ index = "torch-gpu", extra = "gpu" },
]
[[tool.uv.index]]
name = "torch-cpu"
url = "https://download.pytorch.org/whl/cpu"
[[tool.uv.index]]
name = "torch-gpu"
url = "https://download.pytorch.org/whl/cu124"
Development dependencies開発依存関係
Unlike optional dependencies, development dependencies are local-only and will not be included in
the project requirements when published to PyPI or other indexes. As such, development dependencies
are not included in the [project] table.オプションの依存関係とは異なり、開発依存関係はローカル専用であり、PyPIや他のインデックスに公開される際にプロジェクトの要件に含まれません。そのため、開発依存関係は[project]テーブルには含まれません。
Development dependencies can have entries in tool.uv.sources the same as normal dependencies.開発依存関係は、通常の依存関係と同様にtool.uv.sourcesにエントリを持つことができます。
To add a development dependency, use the --dev flag:開発依存関係を追加するには、--devフラグを使用します:
uv uses the [dependency-groups] table (as defined in PEP 735)
for declaration of development dependencies. The above command will create a dev group:uvは、開発依存関係の宣言のためにPEP 735で定義された[dependency-groups]テーブルを使用します。上記のコマンドはdevグループを作成します:
The dev group is special-cased; there are --dev, --only-dev, and --no-dev flags to toggle
inclusion or exclusion of its dependencies. See --no-default-groups to disable all default groups
instead. Additionally, the dev group is synced by default.devグループは特別扱いされます;その依存関係の含めるか除外するかを切り替えるために--dev、--only-dev、および--no-devフラグがあります。すべてのデフォルトグループを無効にするには--no-default-groupsを参照してください。さらに、devグループはデフォルトで同期されます。
Dependency groups依存関係グループ
Development dependencies can be divided into multiple groups, using the --group flag.開発依存関係は、--groupフラグを使用して複数のグループに分けることができます。
For example, to add a development dependency in the lint group:例えば、lintグループに開発依存関係を追加するには:
Which results in the following [dependency-groups] definition:これにより、次の[dependency-groups]定義が生成されます:
Once groups are defined, the --all-groups, --no-default-groups, --group, --only-group, and
--no-group options can be used to include or exclude their dependencies.グループが定義されると、--all-groups、--no-default-groups、--group、--only-group、および
--no-groupオプションを使用して、それらの依存関係を含めたり除外したりできます。
Tipヒント
The --dev, --only-dev, and --no-dev flags are equivalent to --group dev,
--only-group dev, and --no-group dev respectively.--dev、--only-dev、および--no-devフラグは、それぞれ--group dev、--only-group dev、および--no-group devに相当します。
uv requires that all dependency groups are compatible with each other and resolves all groups together when creating the lockfile.uvは、すべての依存関係グループが互換性があることを要求し、ロックファイルを作成する際にすべてのグループを一緒に解決します。
If dependencies declared in one group are not compatible with those in another group, uv will fail to resolve the requirements of the project with an error.1つのグループで宣言された依存関係が別のグループのものと互換性がない場合、uvはプロジェクトの要件を解決できず、エラーが発生します。
Note注意
If you have dependency groups that conflict with one another, resolution will fail unless you explicitly declare them as conflicting.互いに競合する依存関係グループがある場合、明示的に競合として宣言しない限り、解決は失敗します。
Nesting groupsグループのネスト
A dependency group can include other dependency groups, e.g.:依存関係グループは、他の依存関係グループを含むことができます。例えば:
[dependency-groups]
dev = [
{include-group = "lint"},
{include-group = "test"}
]
lint = [
"ruff"
]
test = [
"pytest"
]
An included group's dependencies cannot conflict with the other dependencies declared in a group.含まれているグループの依存関係は、他のグループで宣言された依存関係と衝突してはいけません。
Default groupsデフォルトグループ
By default, uv includes the dev dependency group in the environment (e.g., during uv run or
uv sync). The default groups to include can be changed using the tool.uv.default-groups setting.デフォルトでは、uvは環境にdev依存関係グループを含めます(例:uv runやuv syncの際)。含めるデフォルトグループは、tool.uv.default-groups設定を使用して変更できます。
To enable all dependencies groups by default, use "all" instead of listing group names:すべての依存関係グループをデフォルトで有効にするには、グループ名を列挙する代わりに"all"を使用します:
Tipヒント
To disable this behaviour during uv run or uv sync, use --no-default-groups.
To exclude a specific default group, use --no-group <name>.uv runやuv syncの際にこの動作を無効にするには、--no-default-groupsを使用します。特定のデフォルトグループを除外するには、--no-group <name>を使用します。
Group requires-pythonグループrequires-python
By default, dependency groups must be compatible with your project's requires-python range.デフォルトでは、依存関係グループはプロジェクトのrequires-python範囲と互換性がある必要があります。
If a dependency group requires a different range of Python versions than your project, you can
specify a requires-python for the group in [tool.uv.dependency-groups], e.g.:依存関係グループがプロジェクトとは異なるPythonバージョンの範囲を要求する場合、[tool.uv.dependency-groups]内でグループのためにrequires-pythonを指定できます。例:
[project]
name = "example"
version = "0.0.0"
requires-python = ">=3.10"
[dependency-groups]
dev = ["pytest"]
[tool.uv.dependency-groups]
dev = {requires-python = ">=3.12"}
Legacy dev-dependenciesレガシーdev-dependencies
Before [dependency-groups] was standardized, uv used the tool.uv.dev-dependencies field to
specify development dependencies, e.g.:[dependency-groups]が標準化される前、uvはtool.uv.dev-dependenciesフィールドを使用して開発依存関係を指定していました。例:
Dependencies declared in this section will be combined with the contents in the
dependency-groups.dev. Eventually, the dev-dependencies field will be deprecated and removed.このセクションで宣言された依存関係は、dependency-groups.devの内容と組み合わされます。最終的に、dev-dependenciesフィールドは非推奨となり、削除されます。
Note注意
If a tool.uv.dev-dependencies field exists, uv add --dev will use the existing section
instead of adding a new dependency-groups.dev section.tool.uv.dev-dependenciesフィールドが存在する場合、uv add --devは新しいdependency-groups.devセクションを追加するのではなく、既存のセクションを使用します。
Build dependenciesビルド依存関係
If a project is structured as Python package, it may declare
dependencies that are required to build the project, but not required to run it. These dependencies
are specified in the [build-system] table under build-system.requires, following
PEP 518.プロジェクトがPythonパッケージとして構成されている場合、プロジェクトをビルドするために必要だが、実行するためには必要ない依存関係を宣言することがあります。これらの依存関係は、[build-system]テーブルのbuild-system.requiresに指定され、PEP 518に従います。
For example, if a project uses setuptools as its build backend, it should declare setuptools as
a build dependency:例えば、プロジェクトがsetuptoolsをビルドバックエンドとして使用する場合、setuptoolsをビルド依存関係として宣言する必要があります:
[project]
name = "pandas"
version = "0.1.0"
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
By default, uv will respect tool.uv.sources when resolving build dependencies. For example, to use
a local version of setuptools for building, add the source to tool.uv.sources:デフォルトでは、uvはビルド依存関係を解決する際にtool.uv.sourcesを尊重します。例えば、ビルドのためにローカルバージョンのsetuptoolsを使用するには、ソースをtool.uv.sourcesに追加します:
[project]
name = "pandas"
version = "0.1.0"
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
[tool.uv.sources]
setuptools = { path = "./packages/setuptools" }
When publishing a package, we recommend running uv build --no-sources to ensure that the package
builds correctly when tool.uv.sources is disabled, as is the case when using other build tools,
like pypa/build.パッケージを公開する際には、tool.uv.sourcesが無効になっている場合、他のビルドツール(例えばpypa/build)を使用する際と同様に、パッケージが正しくビルドされることを確認するためにuv build --no-sourcesを実行することをお勧めします。
Editable dependencies編集可能な依存関係
A regular installation of a directory with a Python package first builds a wheel and then installs that wheel into your virtual environment, copying all source files. When the package source files are edited, the virtual environment will contain outdated versions.Pythonパッケージのディレクトリを通常インストールすると、最初にホイールがビルドされ、その後そのホイールが仮想環境にインストールされ、すべてのソースファイルがコピーされます。パッケージのソースファイルが編集されると、仮想環境には古いバージョンが含まれることになります。
Editable installations solve this problem by adding a link to the project within the virtual
environment (a .pth file), which instructs the interpreter to include the source files directly.編集可能なインストールは、この問題を解決するために、仮想環境内にプロジェクトへのリンク(.pthファイル)を追加し、インタープリタにソースファイルを直接含めるよう指示します。
There are some limitations to editables (mainly: the build backend needs to support them, and native modules aren't recompiled before import), but they are useful for development, as the virtual environment will always use the latest changes to the package.editableにはいくつかの制限があります(主に:ビルドバックエンドがそれをサポートする必要があり、ネイティブモジュールはインポート前に再コンパイルされません)が、開発には便利です。仮想環境は常にパッケージの最新の変更を使用します。
uv uses editable installation for workspace packages by default.uvはデフォルトでワークスペースパッケージに対してeditableインストールを使用します。
To add an editable dependency, use the --editable flag:editable依存関係を追加するには、--editableフラグを使用します:
Or, to opt-out of using an editable dependency in a workspace:または、ワークスペースでeditable依存関係の使用をオプトアウトするには:
Virtual dependencies仮想依存関係
uv allows dependencies to be "virtual", in which the dependency itself is not installed as a package, but its dependencies are.uvは依存関係を「仮想」として扱うことを許可します。ここで、依存関係自体はパッケージとしてインストールされず、その依存関係がインストールされます。
By default, dependencies are never virtual.デフォルトでは、依存関係は決して仮想ではありません。
A dependency with a path source can be virtual if it explicitly sets
tool.uv.package = false. Unlike working in the dependent
project with uv, the package will be built even if a build system is
not declared.pathソースを持つ依存関係は、tool.uv.package = falseを明示的に設定することで仮想にすることができます。uvを使用して依存プロジェクト内で作業するのとは異なり、ビルドシステムが宣言されていなくてもパッケージはビルドされます。
To treat a dependency as virtual, set package = false on the source:依存関係を仮想として扱うには、ソースにpackage = falseを設定します:
[project]
dependencies = ["bar"]
[tool.uv.sources]
bar = { path = "../projects/bar", package = false }
If a dependency sets tool.uv.package = false, it can be overridden by declaring package = true
on the source:依存関係がtool.uv.package = falseを設定している場合、ソースにpackage = trueを宣言することで上書きできます:
[project]
dependencies = ["bar"]
[tool.uv.sources]
bar = { path = "../projects/bar", package = true }
Similarly, a dependency with a workspace source can be virtual if it
explicitly sets tool.uv.package = false. The workspace
member will be built even if a build system is not declared.同様に、workspace ソースを持つ依存関係は、tool.uv.package = falseを明示的に設定することで仮想的にすることができます。
ビルドシステムが宣言されていなくても、ワークスペースメンバーはビルドされます。
Workspace members that are not dependencies can be virtual by default, e.g., if the parent
pyproject.toml is:依存関係でないワークスペースメンバーは、デフォルトで仮想的である可能性があります。例えば、親のpyproject.tomlが次のような場合:
[project]
name = "parent"
version = "1.0.0"
dependencies = []
[tool.uv.workspace]
members = ["child"]
And the child pyproject.toml excluded a build system:そして、子のpyproject.tomlがビルドシステムを除外している場合:
Then the child workspace member would not be installed, but the transitive dependency anyio
would be.この場合、childワークスペースメンバーはインストールされませんが、推移的依存関係anyioはインストールされます。
In contrast, if the parent declared a dependency on child:対照的に、親がchildへの依存関係を宣言した場合:
[project]
name = "parent"
version = "1.0.0"
dependencies = ["child"]
[tool.uv.sources]
child = { workspace = true }
[tool.uv.workspace]
members = ["child"]
Then child would be built and installed.この場合、childはビルドされ、インストールされます。
Dependency specifiers依存関係の指定子
uv uses standard dependency specifiers, originally defined in PEP 508. A dependency specifier is composed of, in order:uvは標準の依存関係の指定子を使用します。これは元々PEP 508で定義されました。依存関係の指定子は、次の順序で構成されます:
- The dependency name依存関係の名前
- The extras you want (optional)必要な追加機能(オプション)
- The version specifierバージョン指定子
- An environment marker (optional)環境マーカー(オプション)
The version specifiers are comma separated and added together, e.g., foo >=1.2.3,<2,!=1.4.0 is
interpreted as "a version of foo that's at least 1.2.3, but less than 2, and not 1.4.0".バージョン指定子はカンマで区切られ、組み合わされます。例えば、foo >=1.2.3,<2,!=1.4.0は「fooのバージョンは少なくとも1.2.3で、2未満、かつ1.4.0ではない」と解釈されます。
Specifiers are padded with trailing zeros if required, so foo ==2 matches foo 2.0.0, too.指定子は必要に応じて末尾にゼロが追加されるため、foo ==2はfoo 2.0.0にも一致します。
A star can be used for the last digit with equals, e.g., foo ==2.1.* will accept any release from
the 2.1 series. Similarly, ~= matches where the last digit is equal or higher, e.g., foo ~=1.2
is equal to foo >=1.2,<2, and foo ~=1.2.3 is equal to foo >=1.2.3,<1.3.最後の桁にはアスタリスクを使用でき、等号と組み合わせることができます。例えば、foo ==2.1.*は2.1シリーズの任意のリリースを受け入れます。同様に、~=は最後の桁が等しいかそれ以上の場合に一致します。例えば、foo ~=1.2はfoo >=1.2,<2と等しく、foo ~=1.2.3はfoo >=1.2.3,<1.3と等しくなります。
Extras are comma-separated in square bracket between name and version, e.g.,
pandas[excel,plot] ==2.2. Whitespace between extra names is ignored.エクストラは名前とバージョンの間に角括弧でカンマ区切りで指定されます。例えば、pandas[excel,plot] ==2.2のように。エクストラ名の間の空白は無視されます。
Some dependencies are only required in specific environments, e.g., a specific Python version or
operating system. For example to install the importlib-metadata backport for the
importlib.metadata module, use importlib-metadata >=7.1.0,<8; python_version < '3.10'. To
install colorama on Windows (but omit it on other platforms), use
colorama >=0.4.6,<5; platform_system == "Windows".一部の依存関係は特定の環境でのみ必要です。例えば、特定のPythonバージョンやオペレーティングシステムです。例えば、importlib.metadataモジュールのバックポートをインストールするには、importlib-metadata >=7.1.0,<8; python_version < '3.10'を使用します。Windowsにcoloramaをインストールするには(他のプラットフォームでは省略)、colorama >=0.4.6,<5; platform_system == "Windows"を使用します。
Markers are combined with and, or, and parentheses, e.g.,
aiohttp >=3.7.4,<4; (sys_platform != 'win32' or implementation_name != 'pypy') and python_version >= '3.10'.
Note that versions within markers must be quoted, while versions outside of markers must not be
quoted.マーカーはand、or、および括弧で組み合わされます。例えば、aiohttp >=3.7.4,<4; (sys_platform != 'win32' or implementation_name != 'pypy') and python_version >= '3.10'のように。マーカー内のバージョンは引用符で囲む必要がありますが、マーカー外のバージョンは囲まない必要があります。