| 1 |
####################### |
| 2 |
Environment Variables |
| 3 |
####################### |
| 4 |
|
| 5 |
This reference documents environment variables that affect build's behavior. You can use these to configure private |
| 6 |
package indexes, proxies, SSL certificates, and other settings. |
| 7 |
|
| 8 |
************************ |
| 9 |
Variables Set by build |
| 10 |
************************ |
| 11 |
|
| 12 |
``VIRTUAL_ENV`` |
| 13 |
=============== |
| 14 |
|
| 15 |
build sets this variable when creating `isolated environments |
| 16 |
<https://packaging.python.org/en/latest/glossary/#term-Isolated-Build>`_. It contains the absolute path to the temporary |
| 17 |
`virtual environment <https://docs.python.org/3/tutorial/venv.html>`_ that build creates for installing dependencies. |
| 18 |
Build backends can use this to detect they're running in an isolated environment. |
| 19 |
|
| 20 |
***************************** |
| 21 |
Package Index Configuration |
| 22 |
***************************** |
| 23 |
|
| 24 |
By default, build uses `pip <https://pip.pypa.io/>`_ to install build dependencies in isolated environments. Configure |
| 25 |
pip using these environment variables to work with private package indexes or mirrors. For detailed examples, see |
| 26 |
:doc:`../how-to/corporate-environments`. |
| 27 |
|
| 28 |
.. note:: |
| 29 |
|
| 30 |
These ``PIP_*`` variables only apply when using the default pip installer. When using ``--installer=uv``, configure |
| 31 |
uv through its own `environment variables <https://docs.astral.sh/uv/configuration/environment/>`_ instead (e.g., |
| 32 |
``UV_INDEX_URL``, ``UV_EXTRA_INDEX_URL``). |
| 33 |
|
| 34 |
``PIP_INDEX_URL`` |
| 35 |
================= |
| 36 |
|
| 37 |
Sets the primary `package index <https://packaging.python.org/en/latest/glossary/#term-Package-Index>`_ URL where pip |
| 38 |
looks for packages. Use this to point to private package repositories or PyPI mirrors. Defaults to |
| 39 |
``https://pypi.org/simple``. |
| 40 |
|
| 41 |
.. code-block:: console |
| 42 |
|
| 43 |
$ export PIP_INDEX_URL=https://pypi.company.com/simple |
| 44 |
$ python -m build |
| 45 |
|
| 46 |
``PIP_EXTRA_INDEX_URL`` |
| 47 |
======================= |
| 48 |
|
| 49 |
Adds additional package indexes to search beyond the primary index. This allows using both `PyPI <https://pypi.org/>`_ |
| 50 |
and a private index simultaneously. |
| 51 |
|
| 52 |
.. code-block:: console |
| 53 |
|
| 54 |
$ export PIP_EXTRA_INDEX_URL=https://pypi.company.com/simple |
| 55 |
$ python -m build |
| 56 |
|
| 57 |
.. warning:: |
| 58 |
|
| 59 |
A malicious package on any extra index can shadow packages from other indexes. Use ``PIP_INDEX_URL`` exclusively |
| 60 |
when possible for better security. |
| 61 |
|
| 62 |
``PIP_CERT`` |
| 63 |
============ |
| 64 |
|
| 65 |
Path to a custom CA certificate bundle for SSL/TLS verification. Use this when your organization uses self-signed |
| 66 |
certificates or a custom certificate authority. Defaults to system certificates. |
| 67 |
|
| 68 |
.. code-block:: console |
| 69 |
|
| 70 |
$ export PIP_CERT=/path/to/company-ca-bundle.crt |
| 71 |
$ python -m build |
| 72 |
|
| 73 |
``PIP_TRUSTED_HOST`` |
| 74 |
==================== |
| 75 |
|
| 76 |
Disables SSL verification for the specified host. Only use this in secure development environments where SSL |
| 77 |
certificates aren't available. |
| 78 |
|
| 79 |
.. code-block:: console |
| 80 |
|
| 81 |
$ export PIP_TRUSTED_HOST=pypi.company.com |
| 82 |
$ python -m build |
| 83 |
|
| 84 |
.. warning:: |
| 85 |
|
| 86 |
Disabling SSL verification is insecure. Prefer using ``PIP_CERT`` with proper certificates. |
| 87 |
|
| 88 |
*********************** |
| 89 |
Network Configuration |
| 90 |
*********************** |
| 91 |
|
| 92 |
``PIP_TIMEOUT`` |
| 93 |
=============== |
| 94 |
|
| 95 |
Sets the timeout in seconds for network operations. Increase this on slow or unreliable network connections. Defaults to |
| 96 |
15 seconds. |
| 97 |
|
| 98 |
.. code-block:: console |
| 99 |
|
| 100 |
$ export PIP_TIMEOUT=60 |
| 101 |
$ python -m build |
| 102 |
|
| 103 |
``PIP_RETRIES`` |
| 104 |
=============== |
| 105 |
|
| 106 |
Number of times pip retries failed downloads. Increase this on unstable network connections. Defaults to 5 retries. |
| 107 |
|
| 108 |
.. code-block:: console |
| 109 |
|
| 110 |
$ export PIP_RETRIES=10 |
| 111 |
$ python -m build |
| 112 |
|
| 113 |
``PIP_NO_CACHE_DIR`` |
| 114 |
==================== |
| 115 |
|
| 116 |
Disables pip's package cache directory, forcing fresh downloads every time. Useful in CI environments to ensure |
| 117 |
completely clean builds, though this makes builds slower. |
| 118 |
|
| 119 |
.. code-block:: console |
| 120 |
|
| 121 |
$ export PIP_NO_CACHE_DIR=1 |
| 122 |
$ python -m build |
| 123 |
|
| 124 |
********************* |
| 125 |
Proxy Configuration |
| 126 |
********************* |
| 127 |
|
| 128 |
If you're behind a corporate proxy, configure these variables to route pip's network requests through your proxy server. |
| 129 |
Both uppercase and lowercase versions are recognized. |
| 130 |
|
| 131 |
``HTTP_PROXY`` / ``http_proxy`` |
| 132 |
=============================== |
| 133 |
|
| 134 |
Proxy server for HTTP requests. Specify the proxy URL including protocol and port. |
| 135 |
|
| 136 |
.. code-block:: console |
| 137 |
|
| 138 |
$ export HTTP_PROXY=http://proxy.company.com:8080 |
| 139 |
$ python -m build |
| 140 |
|
| 141 |
``HTTPS_PROXY`` / ``https_proxy`` |
| 142 |
================================= |
| 143 |
|
| 144 |
Proxy server for HTTPS requests. Even though the proxy URL uses ``http://``, this handles HTTPS traffic. |
| 145 |
|
| 146 |
.. code-block:: console |
| 147 |
|
| 148 |
$ export HTTPS_PROXY=http://proxy.company.com:8080 |
| 149 |
$ python -m build |
| 150 |
|
| 151 |
``NO_PROXY`` / ``no_proxy`` |
| 152 |
=========================== |
| 153 |
|
| 154 |
Comma-separated list of hosts that should bypass the proxy. Use this for internal servers that don't require proxy |
| 155 |
access. |
| 156 |
|
| 157 |
.. code-block:: console |
| 158 |
|
| 159 |
$ export NO_PROXY=localhost,127.0.0.1,.company.com |
| 160 |
$ python -m build |
| 161 |
|
| 162 |
*********************************** |
| 163 |
SSL/TLS Certificate Configuration |
| 164 |
*********************************** |
| 165 |
|
| 166 |
These variables configure SSL/TLS certificates for secure connections. Use them when your organization uses self-signed |
| 167 |
certificates or custom certificate authorities. |
| 168 |
|
| 169 |
``REQUESTS_CA_BUNDLE`` |
| 170 |
====================== |
| 171 |
|
| 172 |
Path to custom CA certificate bundle. The `requests <https://requests.readthedocs.io/>`_ library (which `pip |
| 173 |
<https://pip.pypa.io/>`_ depends on) uses this variable. Alternative to ``PIP_CERT``. |
| 174 |
|
| 175 |
.. code-block:: console |
| 176 |
|
| 177 |
$ export REQUESTS_CA_BUNDLE=/path/to/company-ca-bundle.crt |
| 178 |
$ python -m build |
| 179 |
|
| 180 |
``SSL_CERT_FILE`` |
| 181 |
================= |
| 182 |
|
| 183 |
Another variable for specifying a custom CA certificate bundle. Recognized by various Python libraries. |
| 184 |
|
| 185 |
.. code-block:: console |
| 186 |
|
| 187 |
$ export SSL_CERT_FILE=/path/to/company-ca-bundle.crt |
| 188 |
$ python -m build |
| 189 |
|
| 190 |
****************************** |
| 191 |
Python Runtime Configuration |
| 192 |
****************************** |
| 193 |
|
| 194 |
``PYTHONWARNINGS`` |
| 195 |
================== |
| 196 |
|
| 197 |
Controls `Python's warning filters <https://docs.python.org/3/library/warnings.html>`_. Use this in CI to catch |
| 198 |
deprecated features or potential issues in your build configuration by turning warnings into errors. |
| 199 |
|
| 200 |
Catch deprecation warnings: |
| 201 |
|
| 202 |
.. code-block:: console |
| 203 |
|
| 204 |
$ PYTHONWARNINGS=error::DeprecationWarning python -m build |
| 205 |
|
| 206 |
Catch setuptools-specific warnings: |
| 207 |
|
| 208 |
.. code-block:: console |
| 209 |
|
| 210 |
$ PYTHONWARNINGS=error:::setuptools.config.setupcfg python -m build |
| 211 |
|
| 212 |
``PYTHONUTF8`` |
| 213 |
============== |
| 214 |
|
| 215 |
Enables `UTF-8 mode <https://docs.python.org/3/library/os.html#utf-8-mode>`_ on Windows. Use this when building packages |
| 216 |
with non-ASCII characters in filenames or file content on Windows systems. |
| 217 |
|
| 218 |
.. code-block:: console |
| 219 |
|
| 220 |
$ set PYTHONUTF8=1 |
| 221 |
$ python -m build |
| 222 |
|
| 223 |
``TMPDIR`` / ``TEMP`` / ``TMP`` |
| 224 |
=============================== |
| 225 |
|
| 226 |
Controls where build creates the temporary isolated build environment. Useful for debugging or when you need the |
| 227 |
temporary directory on a specific filesystem (e.g., for ccache or compilation caching). |
| 228 |
|
| 229 |
On Unix-like systems, use ``TMPDIR``: |
| 230 |
|
| 231 |
.. code-block:: console |
| 232 |
|
| 233 |
$ TMPDIR=/path/to/custom/tmp python -m build |
| 234 |
|
| 235 |
On Windows, use ``TEMP``: |
| 236 |
|
| 237 |
.. code-block:: console |
| 238 |
|
| 239 |
$ set TEMP=C:\path\to\custom\tmp |
| 240 |
$ python -m build |
| 241 |
|
| 242 |
These variables only change *where* build creates the temporary directory. build still removes its environment when the |
| 243 |
build ends. To pin the environment to a stable path, or to keep it for inspection, use the ``--env-dir`` option instead. |
| 244 |
|
| 245 |
**Common use cases**: |
| 246 |
|
| 247 |
- **Disk space**: Use a different filesystem with more available space |
| 248 |
- **Performance**: Use faster storage (e.g., tmpfs on Linux) |
| 249 |
- **Restricted filesystems**: Point at the writable part of a read-only container |
| 250 |
|
| 251 |
``TMPDIR`` only relocates the base directory; build still appends a random suffix, so the extraction path differs on |
| 252 |
every run. For compiler caches such as ``ccache`` or ``sccache``, which key on the source path, that random suffix is a |
| 253 |
guaranteed cache miss - use ``--sdist-extract-dir`` to pin the path instead. |
| 254 |
|
| 255 |
See :doc:`../how-to/troubleshooting` for debugging examples. |
| 256 |
|
| 257 |
**************************** |
| 258 |
Backend-Specific Variables |
| 259 |
**************************** |
| 260 |
|
| 261 |
Each **build backend** may define its own environment variables for configuration. Check your backend's documentation: |
| 262 |
|
| 263 |
- `Setuptools <https://setuptools.pypa.io/en/latest/userguide/index.html>`_ |
| 264 |
- `Hatchling <https://hatch.pypa.io/latest/config/build/>`_ |
| 265 |
- `PDM-Backend <https://pdm-backend.fming.dev/>`_ |
| 266 |
- `Flit <https://flit.pypa.io/en/stable/>`_ |
| 267 |
- `Poetry-Core <https://python-poetry.org/docs/pyproject/>`_ |
| 268 |
- `scikit-build-core <https://scikit-build-core.readthedocs.io/en/latest/configuration.html>`_ |
| 269 |
- `meson-python <https://meson-python.readthedocs.io/en/latest/reference/config-settings.html>`_ |
| 270 |
|
| 271 |
********************* |
| 272 |
Non-Isolated Builds |
| 273 |
********************* |
| 274 |
|
| 275 |
When using ``--no-isolation``, build skips creating an `isolated environment |
| 276 |
<https://packaging.python.org/en/latest/glossary/#term-Isolated-Build>`_. All environment variables from your current |
| 277 |
shell pass directly to the build backend, including: |
| 278 |
|
| 279 |
- ``PYTHONPATH`` - Affects Python module discovery |
| 280 |
- ``PATH`` - Determines which executables are found |
| 281 |
- Any custom variables your build backend uses |
| 282 |
|
| 283 |
build does not set ``VIRTUAL_ENV`` in this mode. You're responsible for installing build dependencies yourself. See |
| 284 |
:doc:`../how-to/basic-usage` for appropriate use cases. |
| 285 |
|
| 286 |
********************************** |
| 287 |
Alternative: Configuration Files |
| 288 |
********************************** |
| 289 |
|
| 290 |
Instead of environment variables, you can configure `pip <https://pip.pypa.io/>`_ using persistent configuration files. |
| 291 |
This is convenient if you always use the same settings. |
| 292 |
|
| 293 |
**Linux/macOS**: ``~/.config/pip/pip.conf`` |
| 294 |
|
| 295 |
**Windows**: ``%APPDATA%\\pip\\pip.ini`` |
| 296 |
|
| 297 |
Example configuration: |
| 298 |
|
| 299 |
.. code-block:: ini |
| 300 |
|
| 301 |
[global] |
| 302 |
index-url = https://pypi.company.com/simple |
| 303 |
trusted-host = pypi.company.com |
| 304 |
cert = /path/to/company-ca-bundle.crt |
| 305 |
|
| 306 |
For more details and examples, see :doc:`../how-to/corporate-environments` and the `pip configuration documentation |
| 307 |
<https://pip.pypa.io/en/stable/topics/configuration/>`_. |
| 308 |
|
| 309 |
********** |
| 310 |
See also |
| 311 |
********** |
| 312 |
|
| 313 |
- :doc:`../how-to/corporate-environments` for proxy and SSL configuration |
| 314 |
- :doc:`../how-to/troubleshooting` for common issues |
| 315 |
- :doc:`cli` for command-line options |
| 316 |
- `pip documentation <https://pip.pypa.io/en/stable/topics/configuration/>`_ for pip configuration |