일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- CUDA
- Linux
- TORCH
- Mac
- Flask
- Container
- LLM
- Converting
- GitLab
- list
- format
- judge
- KAKAO
- Paper
- Windows
- pytorch
- DB
- numpy
- docker
- Package
- pandas
- Python
- file
- AI
- Laravel
- evaluation
- enV
- Database
- git
- PostgreSQL
Archives
- Today
- Total
Daily Develope
[Python] Install PyTorch & Error Handling on Mac 본문
1. Conda/Anaconda 설치
ㅇ 아나콘다 페이지의 설치환경 및 방법 참고
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
sh Miniconda3-latest-MacOSX-arm64.sh
ㅇ 사용방법
2. pytorch 설치
ㅇ 아키텍처 확인
>>> import platform
>>> platform.platform()
'macOS-15.3.1-x86_64-i386-64bit'
- x86 인 경우 cpuonly 환경 설치 필요
- arm 인 경우 기존(아래) 방법으로 설치
설치 방법 1 - Anaconda (25.02 기준 v2.5 이하 지원)
# case x86) 설치
conda install pytorch torchvision torchaudio cpuonly -c pytorch
# case arm) 설치
conda install pytorch torchvision torchaudio -c pytorch
# 설치 확인
conda list -f pytorch
설치 방법 2 - pip
# Python 3.9 ~ 3.12 (2024년 기준)
pip3 install torch torchvision torchaudio
# osx의 경우 cpu/nlu 사용
pip3 install numpy --pre torch torchvision torchaudio --force-reinstall --index-url https://download.pytorch.org/whl/nightly/cpu
3. 동작 확인
import torch
### mps 사용 가능여부
print(torch.backends.mps.is_available())
### torch 사용 예시
x = torch.rand(5, 3)
print(x)
Error Handling
[2025.02.26]
ㅇ 증상 : import torch 수행 하는 경우 NumPy 버전 오류 발생
A module that was compiled using NumPy 1.x cannot be run in NumPy 2.2.3 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2. |
ㅇ 해결 방법
numpy downgrade
pip uninstall numpy
pip install 'numpy<2'
[2025.02.26]
ㅇ 증상 : numpy의 array 사용이나 mt19937 Random 방식 사용하려는 경우 해당 method 또는 class를 찾을 수 없다는 오류 발생
ㅇ 해결 방법
conda 환경 재생성 후, torch 버전 업그레이드 (기존 pytorch=2.2.2)
# conda env 신규 생성
conda create -n p312 python=3.12
# conda env 변경
conda activate p312
# pytorch v2.5.1 설치
conda install pytorch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 cpuonly -c pytorch
[2025.02.26]
ㅇ 증상 : 모델을 (device=) mpu로 불러오는 경우 오류 발생
ㅇ 해결 방법 : 아키텍처에 맞는 pytorch 설치
'Develope > Python' 카테고리의 다른 글
[Python] ML Flow 정리중 (0) | 2025.03.05 |
---|---|
[Poetry] Poetry 설치 및 기본 명령어 on Mac (2) | 2025.03.05 |
[Python] 반올림 (0) | 2024.08.20 |
[Python] 엑셀 파일 다루기 with Pandas (0) | 2024.01.22 |
[Python] Pickle library (object serialization) (1) | 2023.10.17 |
Comments