Skip to content

Managing Python distributionsPythonディストリビューションの管理


The python command group provides a set of commands to manage Python distributions that may be used by other tools.このpythonコマンドグループは、他のツールによって使用される可能性のあるPythonディストリビューションを管理するための一連のコマンドを提供します。

Note注意

When using environments, manual management is not necessary since by default Hatch will automatically download and manage Python distributions internally when a requested version cannot be found.環境を使用する場合、手動管理は必要ありません。デフォルトでは、Hatchは要求されたバージョンが見つからない場合に、Pythonディストリビューションを自動的にダウンロードして内部で管理します。

Location場所

There are two ways to control where Python distributions are installed. Both methods make it so that each installed distribution is placed in a subdirectory of the configured location named after the distribution.Pythonディストリビューションがインストールされる場所を制御する方法は2つあります。どちらの方法でも、インストールされた各ディストリビューションは、設定された場所のサブディレクトリに配置され、そのディストリビューションの名前が付けられます。

  1. The globally configured default directory for Python installations.Pythonインストールのためにグローバルに設定されたデフォルトディレクトリ
  2. The -d/--dir option of every python subcommand, which takes precedence over the default directory.すべてのpythonサブコマンドの-d/--dirオプションは、デフォルトディレクトリよりも優先されます。

Installationインストール

To install a Python distribution, use the python install command. For example:Pythonディストリビューションをインストールするには、python installコマンドを使用します。例えば:

hatch python install 3.12

This will:これにより:

  1. Download the 3.12 Python distribution3.12 Pythonディストリビューションをダウンロードします。
  2. Unpack it into a directory named 3.12 within the configured default directory for Python installationsそれを設定されたデフォルトディレクトリ内の3.12という名前のディレクトリに展開します。
  3. Add the installation to the user PATHインストールをユーザのPATHに追加します

Now its python executable can be used by you or other tools.これで、python 実行可能ファイルをあなたや他のツールが使用できるようになります。

Note注意

For PATH changes to take effect in the current shell, you will need to restart it.現在のシェルでPATHの変更を有効にするには、シェルを再起動する必要があります。

Multiple複数の

You can install multiple Python distributions at once by providing multiple distribution names. For example:複数のディストリビューション名を指定することで、複数のPythonディストリビューションを同時にインストールできます。例えば:

hatch python install 3.12 3.11 pypy3.10

If you would like to install all available Python distributions that are compatible with your system, use all as the distribution name:システムに互換性のあるすべてのPythonディストリビューションをインストールしたい場合は、ディストリビューション名として all を使用してください:

hatch python install all

Tipヒント

The commands for updating and removing also support this functionality.更新 および 削除 のコマンドもこの機能をサポートしています。

Privateプライベート

By default, installing Python distributions will add them to the user PATH. To disable this behavior, use the --private flag like so:デフォルトでは、Pythonディストリビューションをインストールすると、それらがユーザのPATHに追加されます。この動作を無効にするには、次のように --private フラグを使用します:

hatch python install 3.12 --private

This when combined with the directory option can be used to create private, isolated installations.これは、ディレクトリオプション と組み合わせることで、プライベートで孤立したインストールを作成するために使用できます。

Listing distributions配布の一覧

You can see all of the available and installed Python distributions by using the python show command. For example, if you already installed the 3.12 distribution you may see something like this:インストールされているすべてのPython配布を確認するには、python showコマンドを使用します。たとえば、3.12配布をすでにインストールしている場合、次のような出力が表示されることがあります:

$ hatch python show
    Installed
┏━━━━━━┳━━━━━━━━━┓
┃ Name ┃ Version ┃
┡━━━━━━╇━━━━━━━━━┩
│ 3.12 │ 3.12.7  │
└──────┴─────────┘
      Available
┏━━━━━━━━━━┳━━━━━━━━━┓
┃ Name     ┃ Version ┃
┡━━━━━━━━━━╇━━━━━━━━━┩
│ 3.7      │ 3.7.9   │
├──────────┼─────────┤
│ 3.8      │ 3.8.20  │
├──────────┼─────────┤
│ 3.9      │ 3.9.20  │
├──────────┼─────────┤
│ 3.10     │ 3.10.15 │
├──────────┼─────────┤
│ 3.11     │ 3.11.10 │
├──────────┼─────────┤
│ 3.13     │ 3.13.0  │
├──────────┼─────────┤
│ pypy2.7  │ 7.3.15  │
├──────────┼─────────┤
│ pypy3.9  │ 7.3.15  │
├──────────┼─────────┤
│ pypy3.10 │ 7.3.15  │
└──────────┴─────────┘

Finding installationsインストールの検索

The Python executable of an installed distribution can be found by using the python find command. For example:インストールされた配布のPython実行可能ファイルは、python findコマンドを使用して見つけることができます。たとえば:

$ hatch python find 3.12
/home/.local/share/hatch/pythons/3.12/python/bin/python3

You can instead output its parent directory by using the -p/--parent flag:代わりに、-p/--parentフラグを使用して、その親ディレクトリを出力することもできます:

$ hatch python find 3.12 --parent
/home/.local/share/hatch/pythons/3.12/python/bin

This is useful when other tools do not need to use the executable directly but require knowing the directory containing it.これは、他のツールが実行可能ファイルを直接使用する必要がないが、それを含むディレクトリを知る必要がある場合に便利です。

Updates更新

To update installed Python distributions, use the python update command. For example:インストールされたPython配布を更新するには、python updateコマンドを使用します。たとえば:

hatch python update 3.12 3.11 pypy3.10

When there are no updates available for a distribution, a warning will be displayed:配布に利用可能な更新がない場合、警告が表示されます:

$ hatch python update 3.12
The latest version is already installed: 3.12.7

Removal削除

To remove installed Python distributions, use the python remove command. For example:インストールされたPython配布を削除するには、python removeコマンドを使用します。たとえば:

hatch python remove 3.12 3.11 pypy3.10