> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/porters-handbook/di-7-zhang-flavors/7.4.usespython-he-flavors.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
