이 글을 작성하게 된 이유는 드림핵 강의의 sagemath 설치 강의대로 설치를 하려고 하면 정상적으로 설치가 되지 않아서 제가 설치한 방법을 공유하기 위함입니다. 개개인마다의 컴퓨터 환경에 따라, 설치 시기에 따라 아래의 방법대로 해도 정상적으로 설치가 안 될 수도 있습니다.
sage 홈페이지에 접속해 맨 위의 Miniforge를 설치해줍니다.
$ curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
$ bash Miniforge3-$(uname)-$(uname -m).sh
약관 동의를 하고 설치를 완료하면 다음과 같은 메세지가 나옵니다.
Transaction starting
Transaction finished
To activate this environment, use:
micromamba activate /home/user/miniforge3
Or to execute a single command in this environment, use:
micromamba run -p /home/user/miniforge3 mycommand
installation finished.
Do you wish to update your shell profile to automatically initialize conda?
This will activate conda on startup and change the command prompt when activated.
If you'd prefer that conda's base environment not be activated on startup,
run the following command when conda is activated:
conda config --set auto_activate_base false
You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> yes
no change /home/user/miniforge3/condabin/conda
no change /home/user/miniforge3/bin/conda
no change /home/user/miniforge3/bin/conda-env
no change /home/user/miniforge3/bin/activate
no change /home/user/miniforge3/bin/deactivate
no change /home/user/miniforge3/etc/profile.d/conda.sh
no change /home/user/miniforge3/etc/fish/conf.d/conda.fish
no change /home/user/miniforge3/shell/condabin/Conda.psm1
no change /home/user/miniforge3/shell/condabin/conda-hook.ps1
no change /home/user/miniforge3/lib/python3.12/site-packages/xontrib/conda.xsh
no change /home/user/miniforge3/etc/profile.d/conda.csh
modified /home/user/.bashrc
==> For changes to take effect, close and re-open your current shell. <==
Miniforge3-Linux-x86_64.sh: line 517: [: 1
24: integer expression expected
usage: mamba [-h] [-v] [--no-plugins] [-V] COMMAND ...
mamba: error: argument COMMAND: invalid choice: 'shell' (choose from activate, clean, commands, compare, config, create, deactivate, env, export, info, init, install, list, notices, package, doctor, repoquery, remove, uninstall, rename, run, search, update, upgrade)
여기서 홈페이지에 나와있는 그대로 conda create -n sage sage python=X
를 실행하게 되면 conda: command not found
라는 문구가 나옵니다. 이는 conda가 설치는 되었지만, 현재 터미널에서 인식되지 않는 상태로 보통 설치 경로가 PATH에 등록되지 않아서 발생하는 문제입니다.
먼저 conda의 설치 경로를 찾아보겠습니다.
user@DESKTOP-0RSPDC5:~$ find $HOME -name "conda" -type f
/home/user/miniforge3/pkgs/conda-24.11.3-py312h7900ff3_0/condabin/conda
/home/user/miniforge3/pkgs/conda-24.11.3-py312h7900ff3_0/bin/conda
/home/user/miniforge3/condabin/conda
/home/user/miniforge3/bin/conda
저같은 경우 ~/miniforge3/bin/conda
에 설치되어 있습니다. 이걸 PATH에 추가하겠습니다.
echo 'export PATH="$HOME/miniforge3/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
앞에 (base) user@DESKTOP-0RSPDC5:~$
처럼 (base)
가 붙으면 정상적으로 실행이 된 것입니다.
이제 sagemath를 설치하면 됩니다. 여기서 X는 본인의 python 버전을 입력하면 됩니다.
conda create -n sage sage python=X
아래의 메세지가 나오면 설치가 완료된 것입니다.
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate sage
#
# To deactivate an active environment, use
#
# $ conda deactivate
실행시켜보면 잘 작동함을 확인할 수 있습니다.
(base) user@DESKTOP-0RSPDC5:~$ conda activate sage
(sage) user@DESKTOP-0RSPDC5:~$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.5, Release Date: 2024-12-04 │
│ Using Python 3.10.12. Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage:
sagemath를 설치하고 난 후 Ubuntu를 종료했다 다시 실행해도 앞의 (base)
가 계속 붙어있는 것을 확인할 수 있습니다. 이게 불편하신 분들은 아래와 같은 방법으로 conda의 자동 활성화를 끌 수 있습니다.
conda config --set auto_activate_base false
source ~/.bashrc
실행하면 앞의 (base)
가 사라지게 됩니다. sage를 실행할 때는 기존과 마찬가지로 conda activate sage
를 실행하시면 됩니다.