Anaconda とは
Anaconda とは Python 本体やライブラリなどをまとめて扱うディストリビューション(配布物)の一種である。インストールされるパッケージが多いという特徴があるので、 すぐに必要な作業を始められるという利点がある。Miniforgeは、インストールされるパッケージが Anaconda に比べて少ないという特徴がある。
WSL の Anaconda
インストール
Windows Subsystem on Linux の Ubuntu 20.04 LTS に Anaconda を入れた。
https://linuxize.com/post/how-to-install-anaconda-on-ubuntu-20-04/
$ wget -P /tmp https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh
これには私の環境で 2 分 42 秒かかった。
$ sha256sum /tmp/Anaconda3-2020.07-Linux-x86_64.sh
38ce717758b95b3bd0b1797cc6ccfb76f29a90c25bdfa50ee45f11e583edfdbf /tmp/Anaconda3-2020.07-Linux-x86_64.sh
この値と、次のサイトの sha256 の欄と比較する。
一致していれば正しくダウンロードできていることの証明になる。
https://docs.anaconda.com/anaconda/install/hashes/Anaconda3-2020.07-Linux-x86_64.sh-hash/
一致している。
$ bash /tmp/Anaconda3-2020.02-Linux-x86_64.sh Welcome to Anaconda3 2020.07 In order to continue the installation process, please review the license agreement. Please, press ENTER to continue >>> (中略) Do you approve the license terms? [yes|no] [no] >>>
キー入力で yes として Enter キーを押す。
Anaconda3 will now be installed into this location:
/home/username/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/home/username/anaconda3] >>>
このまま Enter キーを押す。
PREFIX=/home/username/anaconda3 Unpacking payload ...
上の画面が出てくるが、その後は多少時間がかかる。次の画面が出てくるので、yes を入力し、 Enter キーを押す。
(中略) Installation finished. Do you wish the installer to initialize Anaconda3 by running conda init? [yes|no] [no]>>>
ここは yes を入力する。これでいったん終わる。 その後、次のコマンドを実行して、新しい環境の初期化を行う。
$ source ~/.bashrc
次のコマンドで、所望のパッケージがインストールされているか、 指定のバージョンより新しいものかを確認する。必要に応じて grep するのもよい。
$ conda list
Windows の Anaconda
アンインストールとインストール
2025-03-05 、今まで Anaconda を入れていたのだがそろそろアップデートをしなければと思って試みたのだが、全然更新されない。しかたなく、すべてアンインストールして、再度最新版を入れ直した。 Anaconda3-2024.10-1-Windows-x86_64.exe である。
jpegtran
Anaconda を入れると、 JPEG の画像変換ができるコマンド jpegtran がもれなくついてくる。 jpegtran は、カラー画像からグレースケール画像への変換が可能である。 Windows のシェルからは次のような使い方が表示される。
C> jpegtran
C:\Users\username\Anaconda3\Library\bin\jpegtran.exe: must name one input and one output file
usage: C:\Users\username\Anaconda3\Library\bin\jpegtran.exe [switches] inputfile outputfile
Switches (names may be abbreviated):
-copy none Copy no extra markers from source file
-copy comments Copy only comment markers (default)
-copy all Copy all extra markers
-optimize Optimize Huffman table (smaller file, but slow compression)
-progressive Create progressive JPEG file
Switches for modifying the image:
-crop WxH+X+Y Crop to a rectangular subarea
-flip [horizontal|vertical] Mirror image (left-right or top-bottom)
-grayscale Reduce to grayscale (omit color data)
-perfect Fail if there is non-transformable edge blocks
-rotate [90|180|270] Rotate image (degrees clockwise)
-scale M/N Scale output image by fraction M/N, eg, 1/8
-transpose Transpose image
-transverse Transverse transpose image
-trim Drop non-transformable edge blocks
-wipe WxH+X+Y Wipe (gray out) a rectangular subarea
Switches for advanced users:
-arithmetic Use arithmetic coding
-restart N Set restart interval in rows, or in blocks with B
-maxmemory N Maximum memory to use (in kbytes)
-outfile name Specify name for output file
-verbose or -debug Emit debug output
Switches for wizards:
-scans file Create multi-scan JPEG per script file
tensorflow
tensorflow を導入することにした。うまくできるだろうか。
C:\Users\Username> conda install tensorflow
Channels:
- defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: | warning libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
failed
LibMambaUnsatisfiableError: Encountered problems while solving:
- nothing provides bleach 1.5.0 needed by tensorboard-1.7.0-py35he025d50_1
Could not solve for environment specs
The following packages are incompatible
├─ pin-1 is installable and it requires
│ └─ python 3.12.* , which can be installed;
└─ tensorflow is not installable because there are no viable options
├─ tensorflow [1.10.0|1.9.0] would require
│ └─ python 3.5.* , which conflicts with any installable versions previously reported;
├─ tensorflow [1.10.0|1.11.0|...|2.1.0] would require
│ └─ python 3.6.* , which conflicts with any installable versions previously reported;
├─ tensorflow [1.13.1|1.14.0|...|2.9.1] would require
│ └─ python 3.7.* , which conflicts with any installable versions previously reported;
├─ tensorflow [1.7.0|1.7.1|1.8.0] would require
│ └─ tensorboard [>=1.7.0,<1.8.0 |>=1.8.0,<1.9.0 ], which requires
│ └─ bleach 1.5.0 , which does not exist (perhaps a missing channel);
├─ tensorflow [2.10.0|2.8.2|2.9.1] would require
│ └─ python 3.10.* , which conflicts with any installable versions previously reported;
├─ tensorflow [2.10.0|2.3.0|...|2.9.1] would require
│ └─ python 3.8.* , which conflicts with any installable versions previously reported;
└─ tensorflow [2.10.0|2.5.0|2.6.0|2.8.2|2.9.1] would require
└─ python 3.9.* , which conflicts with any installable versions previously reported.
C:\Users\Username
tensorflow の導入はあきらめた。ついでに、Anaconda はやはり大きすぎるので Miniforge にしてやりなおそうと思う。
CuPy
CuPy の導入を参照。
仮想環境
インポートするライブラリを切り替えるには、仮想環境を作ればよい。私は anaconda を利用しているので、 この anaconda が入っている前提で述べる。
- 仮想環境の作成
- (base) $ conda create -n 環境名 python(=バージョン) [ライブラリ名1(=バージョン1)] ...
- 仮想環境の起動
- (base) $ conda activate 環境名
- (環境名) $
- 仮想環境の終了
- (環境名) $ conda deactivate
- (base) $
- 仮想環境の削除
- $ conda remove -n 環境名 --all
- 仮想環境の一覧
- $ conda env list
または
$ conda info -e
conda コマンド一覧
Anaconda や Miniconda, miniforge で使う conda コマンドの一覧である。仮想環境の項とも重複する。
(
| コマンド | 説明 | 例 |
|---|---|---|
| activate | conda 環境をアクティベートする | conda activate env_name |
| clean | 未使用パッケージやキャッシュを削除する | |
| commands | List all available conda subcommands (including those from plugins). Generally only used by tab-completion. | |
| compare | conda 環境間のパッケージを比較する | |
| config | .condarc にある設定値を更新する | |
| create | 指定したパッケージの一覧から新しい conda 環境を作成する | conda create -n new_env_name python=3.10 |
| deactivate | 現在のアクティブな conda 環境をデアクティベートする | |
| doctor | 環境のヘルスレポートを表示する | |
| export | 与えられた環境にエクスポートする | |
| info | 現在インストールされている conda についての情報を表示する | |
| init | シェルインタラクションのために conda を初期化する | |
| install | 特定の conda 環境にパッケージの一覧をインストールする | |
| list | conda 環境でインストールしたライブラリ一覧を表示する | |
| notices | Retrieve latest channel notifications. | |
| package | Create low-level conda packages. (EXPERIMENTAL) | |
| remove (uninstall) | 指定した conda 環境からパッケージの一覧を削除する | conda remove -n env_name --all |
| rename | Rename an existing environment. | |
| repoquery | Advanced search for repodata. | |
| run | Run an executable in a conda environment. | |
| search | Search for packages and display associated information using the MatchSpec format. | |
| update (upgrade) | Update conda packages to the latest compatible version. |