| 1 |
######################## |
| 2 |
Corporate Environments |
| 3 |
######################## |
| 4 |
|
| 5 |
This guide covers common scenarios when using build behind corporate firewalls, with private package indexes (custom |
| 6 |
package repositories), or in restricted network environments. |
| 7 |
|
| 8 |
************************* |
| 9 |
Private package indexes |
| 10 |
************************* |
| 11 |
|
| 12 |
Using a private PyPI mirror |
| 13 |
=========================== |
| 14 |
|
| 15 |
Set the ``PIP_INDEX_URL`` `environment variable |
| 16 |
<https://pip.pypa.io/en/stable/topics/configuration/#environment-variables>`_ to point to your private `package index |
| 17 |
<https://packaging.python.org/en/latest/glossary/#term-Package-Index>`_ (an alternative to `PyPI <https://pypi.org/>`_): |
| 18 |
|
| 19 |
.. code-block:: console |
| 20 |
|
| 21 |
$ export PIP_INDEX_URL=https://pypi.company.com/simple |
| 22 |
$ python -m build |
| 23 |
|
| 24 |
Or for a single command: |
| 25 |
|
| 26 |
.. code-block:: console |
| 27 |
|
| 28 |
$ PIP_INDEX_URL=https://pypi.company.com/simple python -m build |
| 29 |
|
| 30 |
Additional indexes |
| 31 |
================== |
| 32 |
|
| 33 |
To use both PyPI and a private index: |
| 34 |
|
| 35 |
.. code-block:: console |
| 36 |
|
| 37 |
$ export PIP_INDEX_URL=https://pypi.org/simple |
| 38 |
$ export PIP_EXTRA_INDEX_URL=https://pypi.company.com/simple |
| 39 |
$ python -m build |
| 40 |
|
| 41 |
.. warning:: |
| 42 |
|
| 43 |
Using ``PIP_EXTRA_INDEX_URL`` has security implications. A malicious package on any index can shadow packages from |
| 44 |
other indexes. Use ``PIP_INDEX_URL`` exclusively when possible. |
| 45 |
|
| 46 |
**************** |
| 47 |
Authentication |
| 48 |
**************** |
| 49 |
|
| 50 |
Embedded credentials |
| 51 |
==================== |
| 52 |
|
| 53 |
You can embed credentials directly in the index URL: |
| 54 |
|
| 55 |
.. code-block:: console |
| 56 |
|
| 57 |
$ PIP_INDEX_URL=https://username:[email protected]/simple python -m build |
| 58 |
|
| 59 |
.. warning:: |
| 60 |
|
| 61 |
Be careful with embedded credentials in shell history and CI logs. Use environment variable substitution when |
| 62 |
possible: |
| 63 |
|
| 64 |
.. code-block:: console |
| 65 |
|
| 66 |
$ PIP_INDEX_URL=https://${PYPI_USER}:${PYPI_TOKEN}@pypi.company.com/simple python -m build |
| 67 |
|
| 68 |
Using keyring |
| 69 |
============= |
| 70 |
|
| 71 |
Build passes ``--no-input`` to pip, preventing hidden credential prompts that cause the process to appear stuck. When |
| 72 |
the ``keyring`` CLI is available on ``PATH``, build automatically sets ``PIP_KEYRING_PROVIDER=subprocess`` (or |
| 73 |
``UV_KEYRING_PROVIDER=subprocess`` when using the uv installer) so the installer delegates credential lookups to the |
| 74 |
system keyring without needing keyring installed inside the isolated build environment. |
| 75 |
|
| 76 |
Install keyring system-wide so it is available on ``PATH``: |
| 77 |
|
| 78 |
.. code-block:: console |
| 79 |
|
| 80 |
$ pipx install keyring |
| 81 |
|
| 82 |
Or install build with the keyring extra: |
| 83 |
|
| 84 |
.. code-block:: console |
| 85 |
|
| 86 |
$ pip install build[keyring] |
| 87 |
|
| 88 |
Then store your credentials: |
| 89 |
|
| 90 |
.. code-block:: console |
| 91 |
|
| 92 |
$ keyring set https://pypi.company.com username |
| 93 |
|
| 94 |
For specialized backends (e.g., Google Artifact Registry, Azure Artifacts), install the corresponding keyring plugin |
| 95 |
alongside keyring: |
| 96 |
|
| 97 |
.. code-block:: console |
| 98 |
|
| 99 |
$ pipx install keyring |
| 100 |
$ pipx inject keyring keyrings.google-artifactregistry-auth |
| 101 |
|
| 102 |
You can also set the keyring provider explicitly via environment variable, which is useful in CI or when keyring is |
| 103 |
installed in a non-standard location: |
| 104 |
|
| 105 |
.. code-block:: console |
| 106 |
|
| 107 |
$ export PIP_KEYRING_PROVIDER=subprocess # for pip installer |
| 108 |
$ export UV_KEYRING_PROVIDER=subprocess # for uv installer |
| 109 |
$ python -m build |
| 110 |
|
| 111 |
To disable keyring entirely: |
| 112 |
|
| 113 |
.. code-block:: console |
| 114 |
|
| 115 |
$ export PIP_KEYRING_PROVIDER=disabled |
| 116 |
$ export UV_KEYRING_PROVIDER=disabled |
| 117 |
$ python -m build |
| 118 |
|
| 119 |
Using .netrc |
| 120 |
============ |
| 121 |
|
| 122 |
Create a ``~/.netrc`` file (``~/_netrc`` on Windows) with your credentials: |
| 123 |
|
| 124 |
.. code-block:: text |
| 125 |
|
| 126 |
machine pypi.company.com |
| 127 |
login username |
| 128 |
password your-password |
| 129 |
|
| 130 |
Ensure the file has restricted permissions: |
| 131 |
|
| 132 |
.. code-block:: console |
| 133 |
|
| 134 |
$ chmod 600 ~/.netrc |
| 135 |
|
| 136 |
********************** |
| 137 |
SSL/TLS certificates |
| 138 |
********************** |
| 139 |
|
| 140 |
Custom CA certificates |
| 141 |
====================== |
| 142 |
|
| 143 |
If your company uses a custom CA certificate: |
| 144 |
|
| 145 |
.. code-block:: console |
| 146 |
|
| 147 |
$ export REQUESTS_CA_BUNDLE=/path/to/company-ca-bundle.crt |
| 148 |
$ python -m build |
| 149 |
|
| 150 |
Or use pip's certificate option: |
| 151 |
|
| 152 |
.. code-block:: console |
| 153 |
|
| 154 |
$ export PIP_CERT=/path/to/company-ca-bundle.crt |
| 155 |
$ python -m build |
| 156 |
|
| 157 |
Self-signed certificates |
| 158 |
======================== |
| 159 |
|
| 160 |
For development environments with self-signed certificates (not recommended for production): |
| 161 |
|
| 162 |
.. code-block:: console |
| 163 |
|
| 164 |
$ export PIP_TRUSTED_HOST=pypi.company.com |
| 165 |
$ python -m build |
| 166 |
|
| 167 |
Using virtualenv for better SSL support |
| 168 |
======================================= |
| 169 |
|
| 170 |
If you encounter SSL/TLS errors with Python's built-in venv, install virtualenv: |
| 171 |
|
| 172 |
.. code-block:: console |
| 173 |
|
| 174 |
$ pip install build[virtualenv] |
| 175 |
|
| 176 |
This provides a more recent version of pip with better SSL support and truststore capabilities. |
| 177 |
|
| 178 |
.. note:: |
| 179 |
|
| 180 |
Python 3.11.8+ and 3.12.2+ have improved SSL support and may not need this workaround. |
| 181 |
|
| 182 |
*************** |
| 183 |
Proxy servers |
| 184 |
*************** |
| 185 |
|
| 186 |
HTTP/HTTPS proxies |
| 187 |
================== |
| 188 |
|
| 189 |
Configure proxy environment variables: |
| 190 |
|
| 191 |
.. code-block:: console |
| 192 |
|
| 193 |
$ export HTTP_PROXY=http://proxy.company.com:8080 |
| 194 |
$ export HTTPS_PROXY=http://proxy.company.com:8080 |
| 195 |
$ python -m build |
| 196 |
|
| 197 |
With authentication: |
| 198 |
|
| 199 |
.. code-block:: console |
| 200 |
|
| 201 |
$ export HTTP_PROXY=http://user:[email protected]:8080 |
| 202 |
$ export HTTPS_PROXY=http://user:[email protected]:8080 |
| 203 |
|
| 204 |
No proxy for certain hosts |
| 205 |
========================== |
| 206 |
|
| 207 |
.. code-block:: console |
| 208 |
|
| 209 |
$ export NO_PROXY=localhost,127.0.0.1,.company.com |
| 210 |
$ python -m build |
| 211 |
|
| 212 |
************************* |
| 213 |
pip configuration files |
| 214 |
************************* |
| 215 |
|
| 216 |
Global configuration |
| 217 |
==================== |
| 218 |
|
| 219 |
Instead of environment variables, you can create a pip configuration file. |
| 220 |
|
| 221 |
On Linux/macOS (``~/.config/pip/pip.conf``): |
| 222 |
|
| 223 |
.. code-block:: ini |
| 224 |
|
| 225 |
[global] |
| 226 |
index-url = https://pypi.company.com/simple |
| 227 |
trusted-host = pypi.company.com |
| 228 |
cert = /path/to/company-ca-bundle.crt |
| 229 |
|
| 230 |
On Windows (``%APPDATA%\\pip\\pip.ini``): |
| 231 |
|
| 232 |
.. code-block:: ini |
| 233 |
|
| 234 |
[global] |
| 235 |
index-url = https://pypi.company.com/simple |
| 236 |
trusted-host = pypi.company.com |
| 237 |
cert = C:\\path\\to\\company-ca-bundle.crt |
| 238 |
|
| 239 |
Per-project configuration |
| 240 |
========================= |
| 241 |
|
| 242 |
Create a ``pip.conf`` file in your project directory. This is useful for team settings. |
| 243 |
|
| 244 |
************************* |
| 245 |
Air-gapped environments |
| 246 |
************************* |
| 247 |
|
| 248 |
For completely offline builds, you must manually install dependencies first: |
| 249 |
|
| 250 |
.. code-block:: console |
| 251 |
|
| 252 |
$ pip install setuptools wheel your-build-backend |
| 253 |
$ python -m build --no-isolation |
| 254 |
|
| 255 |
The ``--no-isolation`` flag tells build to use your current environment instead of creating an isolated one. |
| 256 |
|
| 257 |
.. warning:: |
| 258 |
|
| 259 |
When using ``--no-isolation``, ensure all build dependencies are installed and compatible. |
| 260 |
|
| 261 |
******************** |
| 262 |
CI/CD environments |
| 263 |
******************** |
| 264 |
|
| 265 |
GitHub Actions |
| 266 |
============== |
| 267 |
|
| 268 |
.. code-block:: yaml |
| 269 |
|
| 270 |
- name: Build package |
| 271 |
run: python -m build |
| 272 |
env: |
| 273 |
PIP_INDEX_URL: ${{ secrets.PYPI_INDEX_URL }} |
| 274 |
PIP_CERT: /path/to/cert.crt |
| 275 |
|
| 276 |
GitLab CI |
| 277 |
========= |
| 278 |
|
| 279 |
.. code-block:: yaml |
| 280 |
|
| 281 |
build: |
| 282 |
script: |
| 283 |
- export PIP_INDEX_URL=$PYPI_INDEX_URL |
| 284 |
- python -m build |
| 285 |
|
| 286 |
*************************** |
| 287 |
Catching backend warnings |
| 288 |
*************************** |
| 289 |
|
| 290 |
To catch deprecation warnings from your build backend (useful in CI): |
| 291 |
|
| 292 |
.. code-block:: console |
| 293 |
|
| 294 |
$ PYTHONWARNINGS=error::DeprecationWarning python -m build |
| 295 |
|
| 296 |
Or for setuptools specifically: |
| 297 |
|
| 298 |
.. code-block:: console |
| 299 |
|
| 300 |
$ PYTHONWARNINGS=error:::setuptools.config.setupcfg python -m build |
| 301 |
|
| 302 |
See :doc:`troubleshooting` for more details on warnings. |
| 303 |
|
| 304 |
*************** |
| 305 |
Common issues |
| 306 |
*************** |
| 307 |
|
| 308 |
Build fails with authentication errors |
| 309 |
====================================== |
| 310 |
|
| 311 |
Build passes ``--no-input`` to pip to prevent hidden credential prompts. If your private index requires authentication, |
| 312 |
pip will fail instead of hanging. Configure one of the authentication methods above (embedded credentials, keyring, or |
| 313 |
``.netrc``) to provide credentials non-interactively. |
| 314 |
|
| 315 |
401/403 errors |
| 316 |
============== |
| 317 |
|
| 318 |
Authentication failed. Verify your credentials and ensure they have access to the required packages. |
| 319 |
|
| 320 |
SSL verification failed |
| 321 |
======================= |
| 322 |
|
| 323 |
Your system doesn't trust the certificate. Use ``REQUESTS_CA_BUNDLE`` or ``PIP_CERT`` to provide the CA certificate, or |
| 324 |
install ``build[virtualenv]`` for better SSL support. |
| 325 |
|
| 326 |
Conda environment conflicts |
| 327 |
=========================== |
| 328 |
|
| 329 |
If you're in a conda environment and experiencing venv creation issues: |
| 330 |
|
| 331 |
.. code-block:: console |
| 332 |
|
| 333 |
$ conda deactivate |
| 334 |
$ python -m build |
| 335 |
|
| 336 |
Or use virtualenv: |
| 337 |
|
| 338 |
.. code-block:: console |
| 339 |
|
| 340 |
$ pip install build[virtualenv] |
| 341 |
$ python -m build |
| 342 |
|
| 343 |
********** |
| 344 |
See also |
| 345 |
********** |
| 346 |
|
| 347 |
- :doc:`troubleshooting` for more problem-solving tips |
| 348 |
- :doc:`../reference/environment-variables` for a complete list of environment variables |
| 349 |
- `pip documentation <https://pip.pypa.io/>`_ for more pip configuration options |