본문 바로가기
카테고리 없음

mise로 Python 버전 관리하기

by Z0e 2025. 3. 11.

 

 

기존에는 `pyenv`으로 파이썬 버전을 관리하고, 가상환경을 만들었다. 추가로 `autoenv`로 가상환경 활성화를 자동으로 구성했다.

작업하다보면 python 말고도 다른 언어들도 사용할 때가 있는데 이를 모두 통합하여 관리할 수 있는 `mise`라는 것이 있다고 하여 적용해보고자 한다.

 

 

mise

mise

 

Home | mise-en-place

mise-en-place The front-end to your dev env Pronounced "MEEZ ahn plahs"

mise.jdx.dev

`python` 뿐만 아니라 `node.js`, `ruby`, `cmake` 등 다양한 개발 언어들의 버전 관리 툴

 

설치

curl https://mise.run | sh
# For bash
echo 'eval "$($HOME/.local/bin/mise activate bash)"' >> ~/.bashrc
source ~/.bashrc

# For zsh
echo 'eval "$($HOME/.local/bin/mise activate zsh)"' >> ~/.zshrc
source ~/.zshrc

 

또는

sudo apt update -y && sudo apt install -y gpg sudo wget curl
sudo install -dm 755 /etc/apt/keyrings
wget -qO - https://mise.jdx.dev/gpg-key.pub | gpg --dearmor | sudo tee /etc/apt/keyrings/mise-archive-keyring.gpg 1> /dev/null
echo "deb [signed-by=/etc/apt/keyrings/mise-archive-keyring.gpg arch=amd64] https://mise.jdx.dev/deb stable main" | sudo tee /etc/apt/sources.list.d/mise.list
sudo apt update
sudo apt install -y mise

 

 

런타임 의존 버전 관리

해당 런타임에서 설치 가능한 모든 버전 표시

mise ls-remote <runtime>
mise ls-remote python
mise ls-remote node
mise ls-remote java

 

 

런타임 설치

mise install <runtime>@<version>
mise install python@3.13

 

런타임 전역 설정

mise use -g <runtime>@<version>
# 또는
mise use --global <runtime>@<version>
mise use -g python@3.13

 

런타임 로컬 설정

cd path/to/project

mise use <runtime>@<version>
mise use python@3.13

 

설치된 런타임 확인

설치되어있는 언어들을 확인할 수 있다.

mise ls

 

 

가상환경 자동화

`mise.toml` configuration 파일을 통해 가상환경 자동화를 설정할 수 있다.

[tools]
python = "3.11" # [optional] will be used for the venv

[env]
_.python.venv = ".venv" # relative to this file's directory
_.python.venv = "/root/.venv" # can be absolute
_.python.venv = "{{env.HOME}}/.cache/venv/myproj" # can use templates
_.python.venv = { path = ".venv", create = true } # create the venv if it doesn't exist
_.python.venv = { path = ".venv", create = true, python = "3.10" } # use a specific python version
_.python.venv = { path = ".venv", create = true, python_create_args = ["--without-pip"] } # pass args to python -m venv
_.python.venv = { path = ".venv", create = true, uv_create_args = ["--system-site-packages"] } # pass args to uv venv
# Install seed packages (pip, setuptools, and wheel) into the virtual environment.
_.python.venv = { path = ".venv", create = true, uv_create_args = ['--seed'] }

 

 

mise + uv

`uv` 설치하면 `python -m venv` 명령어 대신 `mise`로 가상환경을 생성할 수 있다.

mise use -g uv@latest

 

Shell autocompletion

echo 'eval "$(uv generate-shell-completion zsh)"' >> ~/.zshrc
echo 'eval "$(uvx --generate-shell-completion zsh)"' >> ~/.zshrc

 

mise.toml

[settings]
python.uv_venv_auto = true

[env]
_.python.venv = { path = ".venv" }

[tools]
uv = 'latest'

 

~/.zshrc

alias ppip="pip"
alias pip="uv pip"

# pip 함수 재정의
function pip() {
  uv pip "$@"
}

# python3 -m pip 명령을 uv pip로 리다이렉트
function python3() {
  if [ "$1" = "-m" ] && [ "$2" = "pip" ]; then
    shift 2  # -m pip 인자 제거
    uv pip "$@"
  else
    /usr/bin/python3 "$@"  # 또는 실제 python3 경로
  fi
}

 

 

Mise + Python Cookbook | mise-en-place

 

mise.jdx.dev

 

 

 

참고

 

Python | mise-en-place

 

mise.jdx.dev