Python:Requirements
Categories
- pip
- Python:Requirements - Python의 pip 설치 시 사용되는 requirements.txt 파일에 대한 설명
- Python:Constraints - Python의 pip 설치 시 사용되는 constraints.txt 파일에 대한 설명
No Binary
위와 같은 기능을 하는 requirements.txt 파일 내용은 다음과 같다:
requirements.txt vs constraints.txt
자세한 내용은 Python:Constraints#requirements.txt vs constraints.txt 항목 참조.
Version specifiers
~=같은 버전 지정 방법. 자세한 내용은 PEP 440#Version specifiers 항목 참조.
Requirements File Format
- Requirements File Format - pip documentation v21.3.1
- Glossary — Python Packaging User Guide # Requirement Specifier
- Stackoverflow - How to format requirements.txt when package source is from specific websites?
여러 사이트의 패키지를 검색하고 싶다면 아래와 같이 작성하면 된다.
# Torch
--find-links https://download.pytorch.org/whl/torch_stable.html
torch==1.5.0+cu101
torchvision==0.6.0+cu101
# Detectron
--find-links https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/index.html
detectron2
Compare Operators
~= 연산자
Adding to the existing answers, I think it's very important to also mention that while
Following is also true
좀 복잡한 제약 조건
opencv-python 의 pyproject.toml 파일을 보면 다음과 같다:
[build-system]
requires = [
"cmake>=3.1",
"numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
"numpy==1.17.0; python_version=='3.7' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
"numpy==1.17.5; python_version=='3.8' and platform_machine != 'aarch64' and platform_machine != 'arm64'",
"numpy==1.19.3; python_version<'3.9' and sys_platform == 'linux' and platform_machine == 'aarch64'",
"numpy==1.21.0; python_version<'3.9' and sys_platform == 'darwin' and platform_machine == 'arm64'",
"numpy>=2.0.0; python_version>='3.9'",
"pip",
"scikit-build>=0.14.0",
"setuptools==59.2.0",
]
또는 setup.py 파일:
install_requires = [
'numpy>=1.13.3; python_version<"3.7"',
'numpy>=1.17.0; python_version>="3.7"', # https://github.com/numpy/numpy/pull/13725
'numpy>=1.17.3; python_version>="3.8"',
'numpy>=1.19.3; python_version>="3.9"',
'numpy>=1.21.2; python_version>="3.10"',
'numpy>=1.19.3; python_version>="3.6" and platform_system=="Linux" and platform_machine=="aarch64"',
'numpy>=1.21.0; python_version<="3.9" and platform_system=="Darwin" and platform_machine=="arm64"',
'numpy>=1.21.4; python_version>="3.10" and platform_system=="Darwin"',
"numpy>=1.23.5; python_version>='3.11'",
"numpy>=1.26.0; python_version>='3.12'"
]
패키지 찾기 플래그
-
--index-url - pip의 기본 인덱스(PyPI)를 대체합니다. 이걸 지정하면 pip은 더 이상 https://pypi.org/simple 을 보지 않고, 지정한 URL 하나만 검색합니다. 하나만 지정 가능하다.
-
--extra-index-url - PEP 503 인덱스 서버 (PyPI와 같은 구조) 를 기본 PyPI 위에 추가 인덱스를 덧붙입니다. pip은 PyPI와 지정한 URL 둘 다 검색하고, 버전이 맞는 패키지를 찾으면 어디서든 가져옵니다. 여러 개 추가 가능
-
--no-index - 모든 인덱스 서버 무시,
--find-links만 사용
-
--find-links - 단순히 wheel 파일이 나열된 HTML 페이지나 디렉토리를 가리킵니다.
| 보안 주의사항 |
| |
-
--no-binary :all: - wheel 무시, 소스에서 빌드 강제
-
--only-binary :all: - sdist 무시, wheel만 허용 (빌드 안 함)
-
--no-binary<pkg> - 특정 패키지만 소스 빌드 강제
-
--only-binary<pkg> - 특정 패키지만 wheel 강제
-
--trusted-host - SSL 검증 건너뛸 호스트 지정 (사내 미러 등)
해시 검사
--require-hashes 를 추가하면 pip에서 모든 패키지의 해시값을 검증하도록 강제합니다:
# requirements.txt
--require-hashes
requests==2.31.0 \
--hash=sha256:942c5a758f98d790eaed1a29cb6eefc7f0edf3fcb0fce8afe0f44064ad1e1b68
certifi==2024.2.2 \
--hash=sha256:dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1