How do you install dependencies from a private index safely?
AdvancedConceptEnvironments, dependencies & packaging
Answer
Use --index-url to point at the private index (which proxies PyPI), not --extra-index-url. With extra indexes pip picks the highest version across all indexes, so an attacker can publish acme-utils 99.0 on public PyPI and win (dependency confusion). Also:
- Pin and hash (
--require-hashes). - Keep credentials out of URLs in files: use
keyring,PIP_INDEX_URLfrom a secret, oraws codeartifact login --tool pip. - Reserve your internal names on PyPI.
More on Environments, dependencies & packaging
What is a virtual environment and why do we always use one?BeginnerWhat does `error: externally-managed-environment` mean?Beginner`requirements.txt` vs `pyproject.toml`: what goes where?IntermediateWhy is `pip freeze > requirements.txt` not a great lock strategy?IntermediateWhat do version specifiers like `~=`, `==`, `>=,<` mean?BeginnerWhat are `pipx` and `uv`, and when do you use them?Intermediate