Pip를 사용하여 PyTorch 설치하는 방법
Min-jun Kim
Dev Intern · Leapcell

Key Takeaways
- PyTorch는 간단한 명령어를 사용하여 pip로 쉽게 설치할 수 있습니다.
- 시스템 및 GPU 지원에 따라 올바른 설치 명령어를 선택하십시오.
- PyTorch가 예상대로 작동하는지 확인하기 위해 항상 설치를 확인하십시오.
Introduction
PyTorch는 Meta AI에서 개발하고 PyTorch Foundation에서 유지 관리하는 널리 사용되는 오픈 소스 딥 러닝 프레임워크입니다. 텐서 연산, 동적 신경망, CUDA 또는 ROCm을 통한 GPU 가속을 지원하며 연구 및 산업에서 널리 사용됩니다.
1. Prerequisites
pip
를 통해 PyTorch를 설치하기 전에 다음이 있는지 확인하십시오.
-
Python(버전 3.9 이상 권장)
-
pip 설치 및 최신 버전:
python -m pip install --upgrade pip
-
(선택 사항) GPU 가속이 필요한 경우 CUDA 지원 NVIDIA GPU 또는 ROCm 지원 AMD GPU
2. Choosing the Right pip install
Command
공식 "Get Started" 페이지로 이동하여 OS, Python 버전 및 컴퓨팅 플랫폼을 선택하십시오. 다음은 설정에 따른 일반적인 설치 명령어입니다.
A. CPU 전용 설치(GPU 없음)
pip3 install torch torchvision torchaudio
최신 안정적인 CPU 버전을 설치합니다. GPU가 없는 시스템에서 쉽고 빠릅니다.
B. CUDA 지원 포함
cu118
을 사용하는 CUDA 버전으로 바꾸십시오(예: cu120
또는 cu117
):
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
--index-url
옵션은 pip
를 PyTorch의 CUDA 지원 바이너리 리포지토리로 가리킵니다.
C. 이전 PyTorch 버전(선택 사항)
특정 과거 버전(예: v2.6.0)이 필요한 경우:
pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu118
자세한 내용은 "이전 버전" 섹션을 참조하십시오.
3. Common Installation Issues
-
지원되지 않는 Python 버전 PyTorch에는 Python 3.9 이상이 필요합니다. 3.10 이상 또는 지원되지 않는 OS를 사용하는 경우
No matching distribution found
가 표시될 수 있습니다. Python을 다운그레이드하거나 Conda를 통해 설치하면 도움이 될 수 있습니다. -
캐시 관련 문제 설치가 실패하면 강제로 새로 설치해 보십시오.
pip install torch --upgrade --force-reinstall --no-cache-dir --index-url https://download.pytorch.org/whl/cu118
이렇게 하면 손상되거나 오래된 캐시된 패키지와 관련된 문제를 해결할 수 있습니다.
-
가상 환경 실수
pip
를 실행하기 전에 항상 가상 환경을 활성화하십시오. 그렇지 않으면 PyTorch가 시스템 Python에 설치될 수 있습니다.
4. Verifying the Installation
설치 후 모든 것이 작동하는지 확인하십시오.
-
패키지 정보 확인
pip3 show torch
-
Python을 시작하고 테스트:
import torch x = torch.rand(5, 3) print(x) print(torch.cuda.is_available())
- 임의 텐서가 인쇄되어야 합니다.
- CUDA가 올바르게 활성화되면
torch.cuda.is_available()
가True
를 반환합니다.
5. Optional: Uninstalling PyTorch
언제든지 PyTorch를 제거하려면:
pip uninstall torch torchvision torchaudio
6. Summary Table
Scenario | Command |
---|---|
CPU-only | pip3 install torch torchvision torchaudio |
CUDA GPU | pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cuXXX |
Specific version | pip install torch==x.y.z torchvision==… --index-url … |
Force reinstall | Add --upgrade --force-reinstall --no-cache-dir |
Verify | pip3 show torch , then test with Python script |
Uninstall | pip uninstall torch torchvision torchaudio |
7. Conclusion
pip를 사용하여 PyTorch를 설치하는 것은 간단합니다.
- Python(3.9+) 및 pip가 있는지 확인합니다.
- CPU 또는 CUDA에 대해 올바른
pip install
명령어를 선택합니다. - 환경을 활성화합니다.
- 간단한 스크립트를 사용하여 설치를 확인합니다.
PyTorch를 설정하면 모델 구축, 훈련 및 GPU 가속 연구를 시작할 수 있습니다. 즐거운 코딩하세요!
FAQs
Use pip with the official command that matches your Python and system requirements.
Import torch in Python and check with torch.cuda.is_available().
Try upgrading pip, using a virtual environment, or adding --no-cache-dir and the correct index URL.
We are Leapcell, your top choice for hosting backend projects.
Leapcell is the Next-Gen Serverless Platform for Web Hosting, Async Tasks, and Redis:
Multi-Language Support
- Develop with Node.js, Python, Go, or Rust.
Deploy unlimited projects for free
- pay only for usage — no requests, no charges.
Unbeatable Cost Efficiency
- Pay-as-you-go with no idle charges.
- Example: $25 supports 6.94M requests at a 60ms average response time.
Streamlined Developer Experience
- Intuitive UI for effortless setup.
- Fully automated CI/CD pipelines and GitOps integration.
- Real-time metrics and logging for actionable insights.
Effortless Scalability and High Performance
- Auto-scaling to handle high concurrency with ease.
- Zero operational overhead — just focus on building.
Explore more in the Documentation!
Follow us on X: @LeapcellHQ