#author("2024-02-29T07:38:13+00:00","default:mizutu","mizutu")
[[私的AI研究会]] > CondaReview
*【復習】Anaconda &color(green){= 編集中 =}; [#cabd226a]
#ref(画像一覧/anaconda-logo.png,right,around,40%,anaconda-logo.png)
#ref(画像一覧/pypi_logo.png,right,around,40%,pypi_logo.png)
 「Anaconda」の使い方をもう一度復習する。~
#divregion( 目 次,open)
#contents
#enddivregion
#clear
RIGHT:&size(12){※ 最終更新:2024/02/27 };


** Anaconda 開発環境 概要 [#j7074b78]

*** conda主要コマンド [#i37106d6]
|>|CENTER:機 能|CENTER:コマンド|h
|パケージ一覧表示|現在の仮想環境のパッケージ一覧表示|conda list|
|~|指定した仮想環境のパッケージ一覧表示|conda list -n py38|
|パッケージの検索|公式リポジトリ内のパッケージを検索|conda search tensorflow|
|~|チャネル内のパッケージを検索|conda search -c conda-forge tensorflow|
|パッケージインストール|公式リポジトリ内のパッケージをインストール|conda install tensorflow|
|~|チャネル内のパッケージをインストール|conda install -c conda-forge  tensorflow|
|~|バージョン指定してインストール|conda install tensorflow=1.15|
|パッケージの更新|パッケージを最新に|conda update tensorflow|
|~|すべてのパッケージを最新に|conda update --all|
|>|パケージのアンインストール|conda uninstall tensorflow|
|>|パケージの削除|conda remove tensorflow|
|仮想環境作成|pythonバージョンを指定して作成|conda create -n py38 python=3.8|
|~|仮想環境をコピーして作成|conda create -n py38 --clone base|
|~|環境設定ファイル(.yaml)から環境を再構築|conda create -n py38 --file package-list.txt|
|>|仮想環境の削除|conda remove -n py38|
|>|仮想環境有効化|conda activate py38|
|>|仮想環境の終了|conda deactivate|
|>|現在の環境を設定ファイル(.yaml)に出力|conda list --export > package-list.txt|
|>|conda のアップデート|conda update -n base conda|
|>|仮想環境の一覧表示|conda info -e|
|>|conda 環境の表示|conda info|

*** pip/pip3 の主要コマンド [#w53209e6]
|CENTER:機 能|CENTER:コマンド|h
|インストール済みのパッケージの詳細確認|pip show <パッケージ名>|
|インストール済みパッケージ名とバージョン一覧|pip list|
|最新版になっていないもののみ表示|pip list –outdate|
|インストール済みパッケージ名とバージョン一覧(パッケージ管理除外)|pip freeze|
|パッケージのインストール|pip install <パッケージ名>|
|複数パッケージのインストール|pip install <パッケージ名> <パッケージ名> ...|
|バージョンを指定してインストール&br;(バージョンを省略するとインストール可能なバージョン表示)|pip install <パッケージ名>==<バージョン>|
|GitHab からインストール|pip install git+<repository-url>|
|パッケージのアップデート|pip install -U <パッケージ名>|
|パッケージのアップデート|pip install –update <パッケージ名>|
|インストール済みパッケージのアンインストール|pip uninstall <パッケージ名>|
|複数インストール済みパッケージのアンインストール|pip uninstall <パッケージ名> <パッケージ名> ... |
|最新ファイルをDL(インストールはしない)|pip download <パッケージ名>|
|pipのバージョン情報を表示|pip -V|
|pipの主要コマンドとオプション一覧を表示|pip help|
|pip コマンドの内容とオプションを表示|pip <コマンド> -h|

*** 仮想環境について [#a4029018]
- 一覧を表示する~
#codeprettify(){{
(base) > conda info -e
# conda environments:
#
base                  *  C:\Users\USER\anaconda3
openvino_dev             C:\Users\USER\anaconda3\envs\openvino_dev
py37                     C:\Users\USER\anaconda3\envs\py37
py38                     C:\Users\USER\anaconda3\envs\py38
py38_gan                 C:\Users\USER\anaconda3\envs\py38_gan
py38a                    C:\Users\USER\anaconda3\envs\py38a
py_learn                 C:\Users\USER\anaconda3\envs\py_learn
}}
    ↑      ↑     ↑~
  仮想環境名  現在の環境 仮想環境ディレクトリの場所~
~
- 仮想環境は下記コマンドの1行目の場所に生成される
#codeprettify(){{
(base) PS > conda config --show envs_dirs
envs_dirs:
  - C:\Users\USER\anaconda3\envs
  - C:\Users\USER\.conda\envs
  - C:\Users\USER\AppData\Local\conda\conda\envs
}}
・下記 conda info コマンドでも確認できる~
・「conda config」により変更が可能~

*** anaconda の設定環境 [#k540fc01]
- 現在の設定を表示する~
#codeprettify(){{
(base) PS > conda info

     active environment : base
    active env location : C:\Users\USER\anaconda3
            shell level : 1
       user config file : C:\Users\USER\.condarc
 populated config files :
          conda version : 24.1.2
    conda-build version : 24.1.2
         python version : 3.9.18.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=x86_64
                          __conda=24.1.2=0
                          __win=0=0
       base environment : C:\Users\USER\anaconda3  (writable)
      conda av data dir : C:\Users\USER\anaconda3\etc\conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : C:\Users\USER\anaconda3\pkgs
                          C:\Users\USER\.conda\pkgs
                          C:\Users\USER\AppData\Local\conda\conda\pkgs
       envs directories : C:\Users\USER\anaconda3\envs
                          C:\Users\USER\.conda\envs
                          C:\Users\USER\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/24.1.2 requests/2.31.0 CPython/3.9.18 Windows/10 Windows/10.0.22631 solver/libmamba conda-libmamba-solver/24.1.0 libmambapy/1.5.6 aau/0.4.3 c/5snNlqzWCTJlZJsEo_5Qkg s/1b_caiWUs1MvdUtXNMyTaw e/kIf1P1TTAzJXAN1T4PJ4Zg
          administrator : False
             netrc file : None
           offline mode : False
}}

***(参考) conda 環境の設定・確認 [#z62685f5]
- anaconda の構成ファイル「.condarc」~
・「conda config --show-sources」で確認できるとなっているが Windows版では表示なし(存在しない?)~
~
- 設定・確認コマンド「conda config」~
・各種パラメータ指定により動作変更が可能~
~
#divregion(「conda config -h」実行ログ)
#codeprettify(){{
(base) PS > conda config -h
usage: conda-script.py config [-h] [--json] [-v] [-q] [--system | --env | --file FILE] [--show [SHOW ...] |
                              --show-sources | --validate | --describe [DESCRIBE ...] | --write-default]
                              [--get [KEY ...] | --append KEY VALUE | --prepend KEY VALUE | --set KEY VALUE | --remove
                              KEY VALUE | --remove-key KEY | --stdin]

Modify configuration values in .condarc.

This is modeled after the git config command.  Writes to the user .condarc
file (C:\Users\USER\.condarc) by default. Use the
--show-sources flag to display all identified configuration locations on
your computer.

optional arguments:
  -h, --help            Show this help message and exit.

Output, Prompt, and Flow Control Options:
  --json                Report all output as json. Suitable for using conda programmatically.
  -v, --verbose         Can be used multiple times. Once for detailed output, twice for INFO logging, thrice for DEBUG
                        logging, four times for TRACE logging.
  -q, --quiet           Do not display progress bar.

Config File Location Selection:
  Without one of these flags, the user config file at 'C:\Users\USER\.condarc' is used.

  --system              Write to the system .condarc file at 'C:\Users\USER\anaconda3\.condarc'.
  --env                 Write to the active conda environment .condarc file (C:\Users\USER\anaconda3). If no
                        environment is active, write to the user config file (C:\Users\USER\.condarc).
  --file FILE           Write to the given file.

Config Subcommands:
  --show [SHOW ...]     Display configuration values as calculated and compiled. If no arguments given, show
                        information for all configuration values.
  --show-sources        Display all identified configuration sources.
  --validate            Validate all configuration sources. Iterates over all .condarc files and checks for parsing
                        errors.
  --describe [DESCRIBE ...]
                        Describe given configuration parameters. If no arguments given, show information for all
                        configuration parameters.
  --write-default       Write the default configuration to a file. Equivalent to `conda config --describe >
                        ~/.condarc`.

Config Modifiers:
  --get [KEY ...]       Get a configuration value.
  --append KEY VALUE    Add one configuration value to the end of a list key.
  --prepend KEY VALUE, --add KEY VALUE
                        Add one configuration value to the beginning of a list key.
  --set KEY VALUE       Set a boolean or string key.
  --remove KEY VALUE    Remove a configuration value from a list key. This removes all instances of the value.
  --remove-key KEY      Remove a configuration key (and all its values).
  --stdin               Apply configuration information given in yaml format piped through stdin.

See `conda config --describe` or https://conda.io/docs/config.html
for details on all the options that can go in .condarc.

Examples:

Display all configuration values as calculated and compiled::

    conda config --show

Display all identified configuration sources::

    conda config --show-sources

Print the descriptions of all available configuration
options to your command line::

    conda config --describe

Print the description for the "channel_priority" configuration
option to your command line::

    conda config --describe channel_priority

Add the conda-canary channel::

    conda config --add channels conda-canary

Set the output verbosity to level 3 (highest) for
the current activate environment::

    conda config --set verbosity 3 --env

Add the 'conda-forge' channel as a backup to 'defaults'::

    conda config --append channels conda-forge
}}
#enddivregion
#divregion(「conda config --show」実行ログ)
#codeprettify(){{
(base) >conda config --show
add_anaconda_token: True
add_pip_as_python_dependency: True
aggressive_update_packages:
  - ca-certificates
  - certifi
  - openssl
allow_conda_downgrades: False
allow_cycles: True
allow_non_channel_urls: False
allow_softlinks: False
allowlist_channels: []
always_copy: False
always_softlink: False
always_yes: None
anaconda_anon_usage: True
anaconda_upload: None
auto_activate_base: True
auto_stack: 0
auto_update_conda: True
bld_path:
changeps1: True
channel_alias: https://conda.anaconda.org
channel_priority: flexible
channel_settings: []
channels:
  - defaults
client_ssl_cert: None
client_ssl_cert_key: None
clobber: False
conda_build: {}
create_default_packages: []
croot: C:\Users\USER\anaconda3\conda-bld
custom_channels:
  pkgs/main: https://repo.anaconda.com
  pkgs/r: https://repo.anaconda.com
  pkgs/msys2: https://repo.anaconda.com
  pkgs/pro: https://repo.anaconda.com
custom_multichannels:
  defaults:
    - https://repo.anaconda.com/pkgs/main
    - https://repo.anaconda.com/pkgs/r
    - https://repo.anaconda.com/pkgs/msys2
  local:
debug: False
default_channels:
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - https://repo.anaconda.com/pkgs/msys2
default_python: 3.9
default_threads: None
deps_modifier: not_set
dev: False
disallowed_packages: []
download_only: False
dry_run: False
enable_private_envs: False
env_prompt: ({default_env})
envs_dirs:
  - C:\Users\USER\anaconda3\envs
  - C:\Users\USER\.conda\envs
  - C:\Users\USER\AppData\Local\conda\conda\envs
error_upload_url: https://conda.io/conda-post/unexpected-error
execute_threads: 1
experimental: []
extra_safety_checks: False
fetch_threads: 5
force: False
force_32bit: False
force_reinstall: False
force_remove: False
ignore_pinned: False
json: False
local_repodata_ttl: 1
migrated_channel_aliases: []
migrated_custom_channels: {}
no_lock: False
no_plugins: False
non_admin_enabled: True
notify_outdated_conda: True
number_channel_notices: 5
offline: False
override_channels_enabled: True
path_conflict: clobber
pinned_packages: []
pip_interop_enabled: False
pkgs_dirs:
  - C:\Users\USER\anaconda3\pkgs
  - C:\Users\USER\.conda\pkgs
  - C:\Users\USER\AppData\Local\conda\conda\pkgs
proxy_servers: {}
quiet: False
register_envs: True
remote_backoff_factor: 1
remote_connect_timeout_secs: 9.15
remote_max_retries: 3
remote_read_timeout_secs: 60.0
repodata_fns:
  - current_repodata.json
  - repodata.json
repodata_threads: None
repodata_use_zst: True
report_errors: None
restore_free_channel: False
rollback_enabled: True
root_prefix: C:\Users\USER\anaconda3
safety_checks: warn
sat_solver: pycosat
separate_format_cache: False
shortcuts: True
shortcuts_only: []
show_channel_urls: None
signing_metadata_url_base: None
solver: libmamba
solver_ignore_timestamps: False
ssl_verify: True
subdir: win-64
subdirs:
  - win-64
  - noarch
target_prefix_override:
trace: False
track_features: []
unsatisfiable_hints: True
unsatisfiable_hints_check_depth: 2
update_modifier: update_specs
use_index_cache: False
use_local: False
use_only_tar_bz2: False
verbosity: 0
verify_threads: 1
}}
#enddivregion

*** anaconda アンインストール [#c14a1453]
 &color(white,black){'' Windows の場合 ''};~
+「プログラムの追加と削除」から「Anaconda3 ... 」をアンインストールする~
`
+ 下記の anaconda 関連ディレクトリに残っているフォルダ(ファイル)があればすべて削除する~
#codeprettify(){{
C:\ProgramData\Anaconda3
C:\Users\USER\.conda
C:\Users\USER\AppData\Local\conda
C:\Users\USER\anaconda3
}}
※ バージョンによって関連ディレクトリの場所は異なる~

*** anaconda のダウンロードとインストール [#q08f8091]
 &color(white,black){'' Windows の場合 ''};~
+ オフィシャルサイト [['''https://www.anaconda.com/products/distribution'''>+https://www.anaconda.com/products/distribution]] にアクセス~
~
#ref(ProjectEnv2/inst_ubuntu2204_30.jpg,left,around,15%,inst_ubuntu2204_30.jpg)
 ● 画面の「Download」ボタンを押してダウンロード~
~
 ● ダウンロード・ファイル名(2024/02/29 現在)~
  '''Anaconda3-2023.09-0-Linux-x86_64.sh'''~
#clear
~
+ インストーラ「Anaconda3-2023.09-0-Windows-x86_64.exe」を実行し手順に従ってインストールする~
~
#ref(ProjectEnv/20230202_000002_001s.jpg,left,around,30%,20230202_000002_001s.jpg)
#ref(ProjectEnv/20230202_000003_001s.jpg,left,around,30%,20230202_000003_001s.jpg)
#ref(ProjectEnv/20230202_000004_001s.jpg,left,around,30%,20230202_000004_001s.jpg)
#ref(ProjectEnv/20230202_000005_001s.jpg,left,around,30%,20230202_000005_001s.jpg)
#clear
#ref(ProjectEnv/20230202_000006_001s.jpg,left,around,30%,20230202_000006_001s.jpg)
#ref(ProjectEnv/20230202_000008_001s.jpg,left,around,30%,20230202_000008_001s.jpg)
#ref(ProjectEnv3/20231215_043714_001s.jpg,left,around,30%,20231215_043714_001s.jpg)
#ref(ProjectEnv/20230202_000010_001s.jpg,left,around,30%,20230202_000010_001s.jpg)
#clear
※ デフォールト設定でインストールする~

*** anaconda 起動の設定 [#l667b52c]
- アプリケーションの実行時に便利なようにターミナル起動時の設定をしておく。~

 &color(white,black){'' Windows の場合 ''};~
#ref(CondaWin/20220107_000001_001s.jpg,left,around,20%,20220107_000001_001s.jpg)
#ref(CondaWin/20220107_000002_001s.jpg,left,around,20%,20220107_000002_001s.jpg)
#clear

 ''≪ PowerShell(推奨)≫''~
+「スタートボタン」を押し「Anaconda Powershell Prompt (anaconda3)」の上で 右クリック → その他 → ファイルの場所を開く を選択する。~
+ 表示されるエクスプローラ上の「Anaconda Powershell Prompt (anaconda3)」で 右クリック → プロパティ を選ぶ。~
+ リンク先の項目を変更する。~
・元の記述~
#codeprettify(){{
%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\Users\<User>\anaconda3' "
}}
・次のように変更 <User> = ユーザー名 X: = anaconda_winを配置したドライブ~
#codeprettify(){{
%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\ProgramData\Anaconda3' ; Set-Location 'X:\anaconda_win' "
}}

 ''≪ コマンドプロンプト ≫''~
+「Anaconda Prompt (anaconda3)」で 右クリック → プロパティ を選ぶ。~
+ リンク先の項目を変更する。~
・元の記述~
#codeprettify(){{
%windir%\System32\cmd.exe "/K" C:\Users\<User>\anaconda3\Scripts\activate.bat C:\\Users\<User>\anaconda3
}}
・次のように変更 <User> = ユーザー名 X: = anaconda_winを配置したドライブ~
#codeprettify(){{
%windir%\System32\cmd.exe "/K" C:\Users\<User>\anaconda3\Scripts\activate.bat C:\\Users\<User>\anaconda3 & cd /d X:\anaconda_win
}}

*** ファイルシステムと anaconda の配置 [#fffbe70a]
 &color(white,black){'' Windows の場合 ''};~
#ref(filesystem_w_m.png,left,around,60%,filesystem_w_m.png)
#clear

 &color(white,black){'' Linux の場合 ''};~
#ref(filesystem_l_m.png,left,around,60%,filesystem_l_m.png)
#clear

#br

** 更新履歴 [#pd5e4ded]
- 2024/02/27 初版
#br

* 参考資料 [#je7aa61b]
- Anaconda~
-- [[condaコマンドチートシート>+https://qiita.com/Kotabrog/items/1262057349627b299321]]~
-- [[Uninstalling Anaconda Distribution>+https://docs.anaconda.com/free/anaconda/install/uninstall/]]~
-- [[Condaのチャンネルとは?>+https://qiita.com/yuj/items/8ce25959427ea97d373b]]~
-- [[Using the .condarc conda configuration file>+https://conda.io/docs/config.html]]~
-- [[かかしのアウトプット練習>+https://kakashibata.hatenablog.jp/entry/2020/09/27/222205]]~

#br