2022年1月22日土曜日

Amazon SageMaker Studio Labでcondaで仮想環境作成

 無事JupiterLabでPythonが使えるようなりましたが、今後色々なパッケージを追加していく上で元に戻せるように方法を調べているとcondaで仮想環境を複数作成する方法がAWSのドキュメントに書いてありました。

早速手順にある”conda env create --name <任意の環境名> python=3.9”をコンソールで入力してみるとSyntaxエラー?

調べてみてcondaの後ろのenvが不要っぽく”conda create --name <任意の環境名> python=3.9”で試してみると無事完了しました、ちなみにその際はAWSドキュメントに記載があるようにターミナル(File→New→Terminal)から実行しました。


(studiolab) studio-lab-user@default:~$ conda create --name <任意の環境名> python=3.9

−−−−−−−−−−−−−−−実行ログ

Collecting package metadata (current_repodata.json): done

Solving environment: done



==> WARNING: A newer version of conda exists. <==

  current version: 4.10.3

  latest version: 4.11.0


Please update conda by running


    $ conda update -n base conda




## Package Plan ##


  environment location: /home/studio-lab-user/.conda/envs/<任意の環境名>


  added / updated specs:

    - python=3.9



The following packages will be downloaded:


    package                    |            build

    ---------------------------|-----------------

    _libgcc_mutex-0.1          |      conda_forge           3 KB  conda-forge

    _openmp_mutex-4.5          |            1_gnu          22 KB  conda-forge

    bzip2-1.0.8                |       h7f98852_4         484 KB  conda-forge

    ld_impl_linux-64-2.36.1    |       hea4e1c9_2         667 KB  conda-forge

    libnsl-2.0.0               |       h7f98852_0          31 KB  conda-forge

    libuuid-2.32.1             |    h7f98852_1000          28 KB  conda-forge

    openssl-3.0.0              |       h7f98852_2         2.9 MB  conda-forge

    pip-21.3.1                 |     pyhd8ed1ab_0         1.2 MB  conda-forge

    python-3.9.9               |h543edf9_0_cpython        27.4 MB  conda-forge

    python_abi-3.9             |           2_cp39           4 KB  conda-forge

    readline-8.1               |       h46c0cb4_0         295 KB  conda-forge

    tk-8.6.11                  |       h27826a3_1         3.3 MB  conda-forge

    xz-5.2.5                   |       h516909a_1         343 KB  conda-forge

    ------------------------------------------------------------

                                           Total:        36.6 MB


The following NEW packages will be INSTALLED:


  _libgcc_mutex      conda-forge/linux-64::_libgcc_mutex-0.1-conda_forge

  _openmp_mutex      conda-forge/linux-64::_openmp_mutex-4.5-1_gnu

  bzip2              conda-forge/linux-64::bzip2-1.0.8-h7f98852_4

  ca-certificates    conda-forge/linux-64::ca-certificates-2021.10.8-ha878542_0

  ld_impl_linux-64   conda-forge/linux-64::ld_impl_linux-64-2.36.1-hea4e1c9_2

  libffi             conda-forge/linux-64::libffi-3.4.2-h7f98852_5

  libgcc-ng          conda-forge/linux-64::libgcc-ng-11.2.0-h1d223b6_11

  libgomp            conda-forge/linux-64::libgomp-11.2.0-h1d223b6_11

  libnsl             conda-forge/linux-64::libnsl-2.0.0-h7f98852_0

  libuuid            conda-forge/linux-64::libuuid-2.32.1-h7f98852_1000

  libzlib            conda-forge/linux-64::libzlib-1.2.11-h36c2ea0_1013

  ncurses            conda-forge/linux-64::ncurses-6.3-h9c3ff4c_0

  openssl            conda-forge/linux-64::openssl-3.0.0-h7f98852_2

  pip                conda-forge/noarch::pip-21.3.1-pyhd8ed1ab_0

  python             conda-forge/linux-64::python-3.9.9-h543edf9_0_cpython

  python_abi         conda-forge/linux-64::python_abi-3.9-2_cp39

  readline           conda-forge/linux-64::readline-8.1-h46c0cb4_0

  setuptools         conda-forge/linux-64::setuptools-60.5.0-py39hf3d152e_0

  sqlite             conda-forge/linux-64::sqlite-3.37.0-h9cd32fc_0

  tk                 conda-forge/linux-64::tk-8.6.11-h27826a3_1

  tzdata             conda-forge/noarch::tzdata-2021e-he74cb21_0

  wheel              conda-forge/noarch::wheel-0.37.1-pyhd8ed1ab_0

  xz                 conda-forge/linux-64::xz-5.2.5-h516909a_1

  zlib               conda-forge/linux-64::zlib-1.2.11-h36c2ea0_1013


Proceed ([y]/n)? y


Downloading and Extracting Packages

xz-5.2.5             | 343 KB    | #################################################### | 100% 

readline-8.1         | 295 KB    | #################################################### | 100% 

libnsl-2.0.0         | 31 KB     | #################################################### | 100% 

_libgcc_mutex-0.1    | 3 KB      | #################################################### | 100% 

_openmp_mutex-4.5    | 22 KB     | #################################################### | 100% 

python_abi-3.9       | 4 KB      | #################################################### | 100% 

tk-8.6.11            | 3.3 MB    | #################################################### | 100% 

python-3.9.9         | 27.4 MB   | #################################################### | 100% 

pip-21.3.1           | 1.2 MB    | #################################################### | 100% 

libuuid-2.32.1       | 28 KB     | #################################################### | 100% 

ld_impl_linux-64-2.3 | 667 KB    | #################################################### | 100% 

bzip2-1.0.8          | 484 KB    | #################################################### | 100% 

openssl-3.0.0        | 2.9 MB    | #################################################### | 100% 

Preparing transaction: done

Verifying transaction: done

Executing transaction: done

#

# To activate this environment, use

#

#     $ conda activate <任意の環境名>

#

# To deactivate an active environment, use

#

#     $ conda deactivate

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−ここまで
■作成されている環境を確認
(studiolab) studio-lab-user@default:~$ conda info -e

# conda environments:
#
default                  /home/studio-lab-user/.conda/envs/default
studiolab             *  /home/studio-lab-user/.conda/envs/studiolab
<任意の環境名>                   /home/studio-lab-user/.conda/envs/<任意の環境名>
base                     /opt/conda

AWSのドキュメントに従い有効化するため"conda activate <任意の環境名>"を実行すると

(studiolab) studio-lab-user@default:~$ conda activate <任意の環境名>
usage: conda [-h] [-V] command ...
conda: error: argument command: invalid choice: 'activate\xa0<任意の環境名>' (choose from 'clean', 'compare', 'config', 'create', 'help', 'info', 'init', 'install', 'list', 'package', 'remove', 'uninstall', 'run', 'search', 'update', 'upgrade')

エラー・・・またか、また調べてみるとcondaのバージョンが上がったせいかshellがbashの場合はcondaではなくsourceコマンドをしようするみたい

(studiolab) studio-lab-user@default:~$ $source activate <任意の環境名>

(<任意の環境名>) studio-lab-user@default:~$ conda info -e
# conda environments:
#
default                  /home/studio-lab-user/.conda/envs/default
studiolab                /home/studio-lab-user/.conda/envs/studiolab
<任意の環境名>               *  /home/studio-lab-user/.conda/envs/<任意の環境名>
base                     /opt/conda

<任意の環境名>の右側に*マークがついて有効になりました。

続けてipykernelをインストール

(<任意の環境名>) studio-lab-user@default:~$ $conda install ipykernel
−−−−−−−−−−−−−−−−−−−−−−−−−−ここから
Collecting package metadata (current_repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.10.3
  latest version: 4.11.0

Please update conda by running

    $ conda update -n base conda



## Package Plan ##

  environment location: /home/studio-lab-user/.conda/envs/<任意の環境名>

  added / updated specs:
    - ipykernel


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    asttokens-2.0.5            |     pyhd8ed1ab_0          21 KB  conda-forge
    backcall-0.2.0             |     pyh9f0ad1d_0          13 KB  conda-forge
    backports-1.0              |             py_2           4 KB  conda-forge
    backports.functools_lru_cache-1.6.4|     pyhd8ed1ab_0           9 KB  conda-forge
    black-21.12b0              |     pyhd8ed1ab_0         122 KB  conda-forge
    click-8.0.3                |   py39hf3d152e_1         147 KB  conda-forge
    dataclasses-0.8            |     pyhc8e2a94_3          10 KB  conda-forge
    debugpy-1.5.1              |   py39he80948d_0         2.0 MB  conda-forge
    entrypoints-0.3            |  pyhd8ed1ab_1003           8 KB  conda-forge
    executing-0.8.2            |     pyhd8ed1ab_0          18 KB  conda-forge
    ipykernel-6.7.0            |   py39hef51801_0         180 KB  conda-forge
    ipython-8.0.1              |   py39hf3d152e_0         1.1 MB  conda-forge
    jedi-0.18.1                |   py39hf3d152e_0         992 KB  conda-forge
    jupyter_core-4.9.1         |   py39hf3d152e_1          80 KB  conda-forge
    libsodium-1.0.18           |       h36c2ea0_1         366 KB  conda-forge
    libstdcxx-ng-11.2.0        |      he4da1e4_11         4.2 MB  conda-forge
    matplotlib-inline-0.1.3    |     pyhd8ed1ab_0          11 KB  conda-forge
    mypy_extensions-0.4.3      |   py39hf3d152e_4          10 KB  conda-forge
    nest-asyncio-1.5.4         |     pyhd8ed1ab_0           9 KB  conda-forge
    parso-0.8.3                |     pyhd8ed1ab_0          69 KB  conda-forge
    pathspec-0.9.0             |     pyhd8ed1ab_0          31 KB  conda-forge
    pexpect-4.8.0              |     pyh9f0ad1d_2          47 KB  conda-forge
    pickleshare-0.7.5          |          py_1003           9 KB  conda-forge
    platformdirs-2.3.0         |     pyhd8ed1ab_0          14 KB  conda-forge
    ptyprocess-0.7.0           |     pyhd3deb0d_0          16 KB  conda-forge
    pure_eval-0.2.1            |     pyhd8ed1ab_1          14 KB  conda-forge
    python-dateutil-2.8.2      |     pyhd8ed1ab_0         240 KB  conda-forge
    pyzmq-22.3.0               |   py39h37b5a0c_1         537 KB  conda-forge
    six-1.16.0                 |     pyh6c4a22f_0          14 KB  conda-forge
    stack_data-0.1.4           |     pyhd8ed1ab_0          21 KB  conda-forge
    tomli-1.2.2                |     pyhd8ed1ab_0          15 KB  conda-forge
    tornado-6.1                |   py39h3811e60_2         646 KB  conda-forge
    traitlets-5.1.1            |     pyhd8ed1ab_0          82 KB  conda-forge
    typed-ast-1.5.1            |   py39h3811e60_0         213 KB  conda-forge
    typing_extensions-4.0.1    |     pyha770c72_0          26 KB  conda-forge
    wcwidth-0.2.5              |     pyh9f0ad1d_2          33 KB  conda-forge
    zeromq-4.3.4               |       h9c3ff4c_1         351 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        11.6 MB

The following NEW packages will be INSTALLED:

  asttokens          conda-forge/noarch::asttokens-2.0.5-pyhd8ed1ab_0
  backcall           conda-forge/noarch::backcall-0.2.0-pyh9f0ad1d_0
  backports          conda-forge/noarch::backports-1.0-py_2
  backports.functoo~ conda-forge/noarch::backports.functools_lru_cache-1.6.4-pyhd8ed1ab_0
  black              conda-forge/noarch::black-21.12b0-pyhd8ed1ab_0
  click              conda-forge/linux-64::click-8.0.3-py39hf3d152e_1
  dataclasses        conda-forge/noarch::dataclasses-0.8-pyhc8e2a94_3
  debugpy            conda-forge/linux-64::debugpy-1.5.1-py39he80948d_0
  decorator          conda-forge/noarch::decorator-5.1.1-pyhd8ed1ab_0
  entrypoints        conda-forge/noarch::entrypoints-0.3-pyhd8ed1ab_1003
  executing          conda-forge/noarch::executing-0.8.2-pyhd8ed1ab_0
  ipykernel          conda-forge/linux-64::ipykernel-6.7.0-py39hef51801_0
  ipython            conda-forge/linux-64::ipython-8.0.1-py39hf3d152e_0
  jedi               conda-forge/linux-64::jedi-0.18.1-py39hf3d152e_0
  jupyter_client     conda-forge/noarch::jupyter_client-7.1.1-pyhd8ed1ab_0
  jupyter_core       conda-forge/linux-64::jupyter_core-4.9.1-py39hf3d152e_1
  libsodium          conda-forge/linux-64::libsodium-1.0.18-h36c2ea0_1
  libstdcxx-ng       conda-forge/linux-64::libstdcxx-ng-11.2.0-he4da1e4_11
  matplotlib-inline  conda-forge/noarch::matplotlib-inline-0.1.3-pyhd8ed1ab_0
  mypy_extensions    conda-forge/linux-64::mypy_extensions-0.4.3-py39hf3d152e_4
  nest-asyncio       conda-forge/noarch::nest-asyncio-1.5.4-pyhd8ed1ab_0
  parso              conda-forge/noarch::parso-0.8.3-pyhd8ed1ab_0
  pathspec           conda-forge/noarch::pathspec-0.9.0-pyhd8ed1ab_0
  pexpect            conda-forge/noarch::pexpect-4.8.0-pyh9f0ad1d_2
  pickleshare        conda-forge/noarch::pickleshare-0.7.5-py_1003
  platformdirs       conda-forge/noarch::platformdirs-2.3.0-pyhd8ed1ab_0
  prompt-toolkit     conda-forge/noarch::prompt-toolkit-3.0.24-pyha770c72_0
  ptyprocess         conda-forge/noarch::ptyprocess-0.7.0-pyhd3deb0d_0
  pure_eval          conda-forge/noarch::pure_eval-0.2.1-pyhd8ed1ab_1
  pygments           conda-forge/noarch::pygments-2.11.2-pyhd8ed1ab_0
  python-dateutil    conda-forge/noarch::python-dateutil-2.8.2-pyhd8ed1ab_0
  pyzmq              conda-forge/linux-64::pyzmq-22.3.0-py39h37b5a0c_1
  six                conda-forge/noarch::six-1.16.0-pyh6c4a22f_0
  stack_data         conda-forge/noarch::stack_data-0.1.4-pyhd8ed1ab_0
  tomli              conda-forge/noarch::tomli-1.2.2-pyhd8ed1ab_0
  tornado            conda-forge/linux-64::tornado-6.1-py39h3811e60_2
  traitlets          conda-forge/noarch::traitlets-5.1.1-pyhd8ed1ab_0
  typed-ast          conda-forge/linux-64::typed-ast-1.5.1-py39h3811e60_0
  typing_extensions  conda-forge/noarch::typing_extensions-4.0.1-pyha770c72_0
  wcwidth            conda-forge/noarch::wcwidth-0.2.5-pyh9f0ad1d_2
  zeromq             conda-forge/linux-64::zeromq-4.3.4-h9c3ff4c_1


Proceed ([y]/n)? y


Downloading and Extracting Packages
click-8.0.3          | 147 KB    | #################################################### | 100% 
dataclasses-0.8      | 10 KB     | #################################################### | 100% 
parso-0.8.3          | 69 KB     | #################################################### | 100% 
nest-asyncio-1.5.4   | 9 KB      | #################################################### | 100% 
pyzmq-22.3.0         | 537 KB    | #################################################### | 100% 
zeromq-4.3.4         | 351 KB    | #################################################### | 100% 
pure_eval-0.2.1      | 14 KB     | #################################################### | 100% 
typing_extensions-4. | 26 KB     | #################################################### | 100% 
ipython-8.0.1        | 1.1 MB    | #################################################### | 100% 
tornado-6.1          | 646 KB    | #################################################### | 100% 
ptyprocess-0.7.0     | 16 KB     | #################################################### | 100% 
backports-1.0        | 4 KB      | #################################################### | 100% 
entrypoints-0.3      | 8 KB      | #################################################### | 100% 
backports.functools_ | 9 KB      | #################################################### | 100% 
traitlets-5.1.1      | 82 KB     | #################################################### | 100% 
six-1.16.0           | 14 KB     | #################################################### | 100% 
asttokens-2.0.5      | 21 KB     | #################################################### | 100% 
jedi-0.18.1          | 992 KB    | #################################################### | 100% 
jupyter_core-4.9.1   | 80 KB     | #################################################### | 100% 
mypy_extensions-0.4. | 10 KB     | #################################################### | 100% 
stack_data-0.1.4     | 21 KB     | #################################################### | 100% 
ipykernel-6.7.0      | 180 KB    | #################################################### | 100% 
typed-ast-1.5.1      | 213 KB    | #################################################### | 100% 
libstdcxx-ng-11.2.0  | 4.2 MB    | #################################################### | 100% 
libsodium-1.0.18     | 366 KB    | #################################################### | 100% 
backcall-0.2.0       | 13 KB     | #################################################### | 100% 
pickleshare-0.7.5    | 9 KB      | #################################################### | 100% 
matplotlib-inline-0. | 11 KB     | #################################################### | 100% 
wcwidth-0.2.5        | 33 KB     | #################################################### | 100% 
python-dateutil-2.8. | 240 KB    | #################################################### | 100% 
debugpy-1.5.1        | 2.0 MB    | #################################################### | 100% 
pathspec-0.9.0       | 31 KB     | #################################################### | 100% 
platformdirs-2.3.0   | 14 KB     | #################################################### | 100% 
tomli-1.2.2          | 15 KB     | #################################################### | 100% 
executing-0.8.2      | 18 KB     | #################################################### | 100% 
pexpect-4.8.0        | 47 KB     | #################################################### | 100% 
black-21.12b0        | 122 KB    | #################################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−ここまで
無事インストールが完了するとJupiterLabのランチャーに<任意の環境名>:PythonのNotebookとコンソールのアイコンが作成されました。

ちなみにインストール途中の警告メッセージ
==> WARNING: A newer version of conda exists. <==

  current version: 4.10.3

  latest version: 4.11.0



Please update conda by running



    $ conda update -n base conda

の指示に従ってupdateしようとするとbaseのフォルダへのアクセス権がなくエラーになりアップデートできませんでした。

0 件のコメント:

コメントを投稿