# 7.4.USES=python 和 Flavors

当使用 [`python`](https://docs.freebsd.org/en/books/porters-handbook/uses/#uses-python) 并设置了 `USE_PYTHON=distutils` 时，Port 会自动填充 `FLAVORS`，其中包含它所支持的 Python 版本。

**示例 7：简单的 `USES=python`**

假设当前支持的 Python 版本是 2.7、3.4、3.5 和 3.6，且默认的 Python 2 和 Python 3 版本分别是 2.7 和 3.6，那么以下写法：

```makefile
USES=	python
USE_PYTHON=	distutils
```

将获得这些 flavor：`py27` 和 `py36`。

```makefile
USES=	python
USE_PYTHON=	distutils allflavors
```

将获得这些 flavor：`py27`、`py34`、`py35` 和 `py36`。

**示例 8：带版本要求的 `USES=python`**

假设当前支持的 Python 版本是 2.7、3.4、3.5 和 3.6，且默认的 Python 2 和 Python 3 版本分别是 2.7 和 3.6，那么以下写法：

```makefile
USES=	python:-3.5
USE_PYTHON=	distutils
```

将获得这个 flavor：`py27`。

```makefile
USES=	python:-3.5
USE_PYTHON=	distutils allflavors
```

将获得这些 flavor：`py27`、`py34` 和 `py35`。

```makefile
USES=	python:3.4+
USE_PYTHON=	distutils
```

将获得这个 flavor：`py36`。

```makefile
USES=	python:3.4+
USE_PYTHON=	distutils allflavors
```

将获得这些 flavor：`py34`、`py35` 和 `py36`。

可以使用 `PY_FLAVOR` 来依赖正确版本的 Python 模块。所有对支持 flavor 的 Python Port 的依赖都应使用 `PY_FLAVOR`，而不是直接使用 `FLAVOR`。

**示例 9：适用于未使用 `distutils` 的 Port**

如果默认的 Python 3 版本是 3.6，以下写法将把 `PY_FLAVOR` 设置为 `py36`：

```makefile
RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}mutagen>0:audio/py-mutagen@${PY_FLAVOR}

USES=	python:3.5+
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://porters-handbook.bsdcn.org/di-7-zhang-flavors/7.4.usespython-he-flavors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
