WSL:【Miniconda】インストール手順
目次
はじめに
前提
- Linux環境
※本手順はWindows環境にWSLをインストールして確認した - 参考
- WSLについての説明記事
- Dockerなどで利用するWSLについて
手順を確認した環境
- WSL2(Windows Subsystem for Linux-Version2)
- Ubuntu
- 参考
手順
準備
インストールスクリプトダウンロード
wget "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh"
--2022-02-12 13:32:24-- https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh Resolving repo.anaconda.com (repo.anaconda.com)... 104.16.131.3, 104.16.130.3, 2606:4700::6810:8303, ... Connecting to repo.anaconda.com (repo.anaconda.com)|104.16.131.3|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 66709754 (64M) [application/x-sh] Saving to: ‘Miniconda3-latest-Linux-x86_64.sh’ Miniconda3-latest-Linux-x86_64.sh 100%[===================================================================>] 63.62M 6.87MB/s in 10s 2022-02-12 13:32:35 (6.11 MB/s) - ‘Miniconda3-latest-Linux-x86_64.sh’ saved [66709754/66709754]
- wget
- インターネット上のファイルをダウンロード
- Linux環境なのでCLIダウンロードを選択
- ダウンロードファイル名は「"」で囲む
- ダウンロードファイルのURL取得方法
- Minicondaダウンロードページ(Miniconda — Conda documentation)に接続
- 「Linux」「Miniconda3 Linux 64-bit」を探す
- 右クリック – リンクのコピー
ダウンロードファイル確認
ls -l
total 65148 -rw-rw-r– 1 futa futa 66709754 Jul 22 2021 Miniconda3-latest-Linux-x86_64.sh
- 「Miniconda3-latest-Linux-x86_64.sh」がダウンロードできた
インストール
スクリプト実行
sh Miniconda3-latest-Linux-x86_64.sh
Welcome to Miniconda3 py39_4.10.3
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>
===================================
End User License Agreement - Miniconda
===================================
(中略)
Do you accept the license terms? [yes|no]
[no] >>> yes
Miniconda3 will now be installed into this location:
/home/futa/miniconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/home/futa/miniconda3] >>>(Enter)
PREFIX=/home/futa/miniconda3
Unpacking payload ...
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/futa/miniconda3
added / updated specs:
- _libgcc_mutex==0.1=main
- _openmp_mutex==4.5=1_gnu
- brotlipy==0.7.0=py39h27cfd23_1003
- ca-certificates==2021.7.5=h06a4308_1
- certifi==2021.5.30=py39h06a4308_0
- cffi==1.14.6=py39h400218f_0
- chardet==4.0.0=py39h06a4308_1003
- conda-package-handling==1.7.3=py39h27cfd23_1
- conda==4.10.3=py39h06a4308_0
- cryptography==3.4.7=py39hd23ed53_0
- idna==2.10=pyhd3eb1b0_0
- ld_impl_linux-64==2.35.1=h7274673_9
- libffi==3.3=he6710b0_2
- libgcc-ng==9.3.0=h5101ec6_17
- libgomp==9.3.0=h5101ec6_17
- libstdcxx-ng==9.3.0=hd4cf53a_17
- ncurses==6.2=he6710b0_1
- openssl==1.1.1k=h27cfd23_0
- pip==21.1.3=py39h06a4308_0
- pycosat==0.6.3=py39h27cfd23_0
- pycparser==2.20=py_2
- pyopenssl==20.0.1=pyhd3eb1b0_1
- pysocks==1.7.1=py39h06a4308_0
- python==3.9.5=h12debd9_4
- readline==8.1=h27cfd23_0
- requests==2.25.1=pyhd3eb1b0_0
- ruamel_yaml==0.15.100=py39h27cfd23_0
- setuptools==52.0.0=py39h06a4308_0
- six==1.16.0=pyhd3eb1b0_0
- sqlite==3.36.0=hc218d9a_0
- tk==8.6.10=hbc83047_0
- tqdm==4.61.2=pyhd3eb1b0_1
- tzdata==2021a=h52ac0ba_0
- urllib3==1.26.6=pyhd3eb1b0_1
- wheel==0.36.2=pyhd3eb1b0_0
- xz==5.2.5=h7b6447c_0
- yaml==0.2.5=h7b6447c_0
- zlib==1.2.11=h7b6447c_3
The following NEW packages will be INSTALLED:
_libgcc_mutex pkgs/main/linux-64::_libgcc_mutex-0.1-main
_openmp_mutex pkgs/main/linux-64::_openmp_mutex-4.5-1_gnu
brotlipy pkgs/main/linux-64::brotlipy-0.7.0-py39h27cfd23_1003
ca-certificates pkgs/main/linux-64::ca-certificates-2021.7.5-h06a4308_1
certifi pkgs/main/linux-64::certifi-2021.5.30-py39h06a4308_0
cffi pkgs/main/linux-64::cffi-1.14.6-py39h400218f_0
chardet pkgs/main/linux-64::chardet-4.0.0-py39h06a4308_1003
conda pkgs/main/linux-64::conda-4.10.3-py39h06a4308_0
conda-package-han~ pkgs/main/linux-64::conda-package-handling-1.7.3-py39h27cfd23_1
cryptography pkgs/main/linux-64::cryptography-3.4.7-py39hd23ed53_0
idna pkgs/main/noarch::idna-2.10-pyhd3eb1b0_0
ld_impl_linux-64 pkgs/main/linux-64::ld_impl_linux-64-2.35.1-h7274673_9
libffi pkgs/main/linux-64::libffi-3.3-he6710b0_2
libgcc-ng pkgs/main/linux-64::libgcc-ng-9.3.0-h5101ec6_17
libgomp pkgs/main/linux-64::libgomp-9.3.0-h5101ec6_17
libstdcxx-ng pkgs/main/linux-64::libstdcxx-ng-9.3.0-hd4cf53a_17
ncurses pkgs/main/linux-64::ncurses-6.2-he6710b0_1
openssl pkgs/main/linux-64::openssl-1.1.1k-h27cfd23_0
pip pkgs/main/linux-64::pip-21.1.3-py39h06a4308_0
pycosat pkgs/main/linux-64::pycosat-0.6.3-py39h27cfd23_0
pycparser pkgs/main/noarch::pycparser-2.20-py_2
pyopenssl pkgs/main/noarch::pyopenssl-20.0.1-pyhd3eb1b0_1
pysocks pkgs/main/linux-64::pysocks-1.7.1-py39h06a4308_0
python pkgs/main/linux-64::python-3.9.5-h12debd9_4
readline pkgs/main/linux-64::readline-8.1-h27cfd23_0
requests pkgs/main/noarch::requests-2.25.1-pyhd3eb1b0_0
ruamel_yaml pkgs/main/linux-64::ruamel_yaml-0.15.100-py39h27cfd23_0
setuptools pkgs/main/linux-64::setuptools-52.0.0-py39h06a4308_0
six pkgs/main/noarch::six-1.16.0-pyhd3eb1b0_0
sqlite pkgs/main/linux-64::sqlite-3.36.0-hc218d9a_0
tk pkgs/main/linux-64::tk-8.6.10-hbc83047_0
tqdm pkgs/main/noarch::tqdm-4.61.2-pyhd3eb1b0_1
tzdata pkgs/main/noarch::tzdata-2021a-h52ac0ba_0
urllib3 pkgs/main/noarch::urllib3-1.26.6-pyhd3eb1b0_1
wheel pkgs/main/noarch::wheel-0.36.2-pyhd3eb1b0_0
xz pkgs/main/linux-64::xz-5.2.5-h7b6447c_0
yaml pkgs/main/linux-64::yaml-0.2.5-h7b6447c_0
zlib pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3
Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> yes
Miniconda3-latest-Linux-x86_64.sh: 472: [[: not found
no change /home/futa/miniconda3/condabin/conda
no change /home/futa/miniconda3/bin/conda
no change /home/futa/miniconda3/bin/conda-env
no change /home/futa/miniconda3/bin/activate
no change /home/futa/miniconda3/bin/deactivate
no change /home/futa/miniconda3/etc/profile.d/conda.sh
no change /home/futa/miniconda3/etc/fish/conf.d/conda.fish
no change /home/futa/miniconda3/shell/condabin/Conda.psm1
no change /home/futa/miniconda3/shell/condabin/conda-hook.ps1
no change /home/futa/miniconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change /home/futa/miniconda3/etc/profile.d/conda.csh
modified /home/futa/.bashrc
==> For changes to take effect, close and re-open your current shell. <==
If you'd prefer that conda's base environment not be activated on startup,
set the auto_activate_base parameter to false:
conda config --set auto_activate_base false
Thank you for installing Miniconda3!
- sh
- ファイルをshell実行
- ダウンロードした「Miniconda3-latest-Linux-x86_64.sh」を指定する
- 確認3回
- ライセンス同意
- 「yes」入力
- インストール先ディレクトリ
- 「Enter」(カレントディレクトリにインストール)
- 変更する場合はディレクトリを入力して「Enter」
- initに登録するか
- 「yes」入力(Linux起動時にサービス起動される)
- ライセンス同意
- インストール先
- インストールログより[/home/futa/miniconda3]
ディレクトリ確認
ls -l
total 65152 -rw-rw-r-- 1 futa futa 66709754 Jul 22 2021 Miniconda3-latest-Linux-x86_64.sh drwxrwxr-x 16 futa futa 4096 Feb 12 14:13 miniconda3
- 「miniiconda3」ディレクトリが作成されている
- 補足
- Linuxのファイル属性表示
- drwxrwxr-x:先頭が「d」はディレクトリ
- -rw-rw-r-:先頭が「-」はファイル
- Linuxのファイル属性表示
事後確認
ターミナル再接続
- ターミナルを切断
- GUI接続
- すべてのアプリ – Ubuntu
- CLI接続
- コマンドプロンプロ(またはPowerShell)
- 「wsl」入力(既定のLinuxに接続)
- 補足
- 再起動を促すメッセージはログにも出力されている
- 「==> For changes to take effect, close and re-open your current shell. <==」
インストール後確認
path確認
which conda
/home/futa/miniconda3/bin/conda
- インストールディレクトリが表示されている
- Minicondaが使える状態になっている
- which
- インストールアプリのパスが通っているか確認するLinuxコマンド
- パスが通っていないとフルパス指定が必要
- 補足
- ターミナル再接続なしではダメだった
conda listで確認
conda list
# packages in environment at /home/futa/miniconda3: # # Name Version Build Channel _libgcc_mutex 0.1 main _openmp_mutex 4.5 1_gnu brotlipy 0.7.0 py39h27cfd23_1003 ca-certificates 2021.7.5 h06a4308_1 certifi 2021.5.30 py39h06a4308_0 cffi 1.14.6 py39h400218f_0 chardet 4.0.0 py39h06a4308_1003 conda 4.10.3 py39h06a4308_0 conda-package-handling 1.7.3 py39h27cfd23_1 cryptography 3.4.7 py39hd23ed53_0 idna 2.10 pyhd3eb1b0_0 ld_impl_linux-64 2.35.1 h7274673_9 libffi 3.3 he6710b0_2 libgcc-ng 9.3.0 h5101ec6_17 libgomp 9.3.0 h5101ec6_17 libstdcxx-ng 9.3.0 hd4cf53a_17 ncurses 6.2 he6710b0_1 openssl 1.1.1k h27cfd23_0 pip 21.1.3 py39h06a4308_0 pycosat 0.6.3 py39h27cfd23_0 pycparser 2.20 py_2 pyopenssl 20.0.1 pyhd3eb1b0_1 pysocks 1.7.1 py39h06a4308_0 python 3.9.5 h12debd9_4 readline 8.1 h27cfd23_0 requests 2.25.1 pyhd3eb1b0_0 ruamel_yaml 0.15.100 py39h27cfd23_0 setuptools 52.0.0 py39h06a4308_0 six 1.16.0 pyhd3eb1b0_0 sqlite 3.36.0 hc218d9a_0 tk 8.6.10 hbc83047_0 tqdm 4.61.2 pyhd3eb1b0_1 tzdata 2021a h52ac0ba_0 urllib3 1.26.6 pyhd3eb1b0_1 wheel 0.36.2 pyhd3eb1b0_0 xz 5.2.5 h7b6447c_0 yaml 0.2.5 h7b6447c_0 zlib 1.2.11 h7b6447c_3
- conda list
- pythonライブラリがインストールされているか確認するコマンド
- 一覧表示されたのでMinicondaの動作も問題ないことが分かる
- 補足
- 表示が長いので「grep」や「less」も併用するのがよい
- 例:「conda list|grep」、「conda list|less」
追加設定
shell機能追加(必要あれば)
conda init fish
no change /home/futa/miniconda3/condabin/conda no change /home/futa/miniconda3/bin/conda no change /home/futa/miniconda3/bin/conda-env no change /home/futa/miniconda3/bin/activate no change /home/futa/miniconda3/bin/deactivate no change /home/futa/miniconda3/etc/profile.d/conda.sh no change /home/futa/miniconda3/etc/fish/conf.d/conda.fish no change /home/futa/miniconda3/shell/condabin/Conda.psm1 no change /home/futa/miniconda3/shell/condabin/conda-hook.ps1 no change /home/futa/miniconda3/lib/python3.9/site-packages/xontrib/conda.xsh no change /home/futa/miniconda3/etc/profile.d/conda.csh modified /home/futa/.config/fish/config.fish ==> For changes to take effect, close and re-open your current shell. <==
- conda init fish
- 「fish」ファイルが更新された
- ターミナルを再接続する
- 補足
- fish …… プロンプト変更、シンタックスハイライト、TAB入力補完など
- リファレンス にあるMinicondaのインストール手順にある操作
ちょっと遊ぶ
NumPy
インストール確認確認
conda list|grep numpy
- 出力なし
- NumPyはインストールされていない
インストール
conda install numpy
conda list|grep numpy
numpy 1.21.2 py39h20f2e39_0 numpy-base 1.21.2 py39h79a1101_0
- Numpyがインストールされた
- installの出力結果は省略した
実行
python
- プロンプトが対話式に切り替わる
- 続けて以下のコマンドを実行
import numpy as np
np.arange(10)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
- import numpy as np
- NumPyがインポートできた
- np.arange(10)
- NumPyコマンドが実行できた
- 補足
- IPythonも使えた方がいいので、後でインストール
- conda install ipython
- 参考
- NumPyコマンドの説明記事
- 上記例に使用したnp.arangeの説明
- NumPyコマンドの説明記事
リファレンス
- Miniconda — Conda documentation
- ダウンロードページ
- Installing on Linux — conda 4.11.0.post37+c75b4b561 documentation
- インストール手順

