0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MacでPython始めるときコマンドを覚えるのが面倒なのでメモする

Posted at
% brew install python3

# プロジェクト用のディレクトリに移動するんやで
% python3 -m venv .venv

# activateするんやで
% pip install -U pip
% pip install jupyterlab

ついでにGPUサーバの設定する

※ここからはUbuntuです

dockerインストールする

$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates  curl gnupg lsb-release
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
$ echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo groupadd docker
$ sudo usermod -aG docker $USER

***LOGOUT***
***RELOGIN***

$ sudo systemctl enable docker.service
$ sudo systemctl enable containerd.service
$ curl https://get.docker.com | sh \
  && sudo systemctl --now enable docker

参考:https://docs.docker.com/engine/install/ubuntu/

NVIDIAドライバインストールする

$ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:03.1/0000:09:00.0 ==
modalias : pci:v000010DEd00002504sv000010DEsd00001536bc03sc00i00
vendor   : NVIDIA Corporation
driver   : nvidia-driver-470-server - distro non-free
driver   : nvidia-driver-470 - distro non-free recommended
driver   : nvidia-driver-460-server - distro non-free
driver   : nvidia-driver-460 - distro non-free
driver   : xserver-xorg-video-nouveau - distro free builtin
$ sudo add-apt-repository ppa:graphics-drivers
$ sudo apt update
$ sudo apt install nvidia-driver-470-server
$ sudo reboot

CUDAドライバインストールする

$ sudo apt-get install linux-headers-$(uname -r)
$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID | sed -e 's/\.//g')
$ wget https://developer.download.nvidia.com/compute/cuda/repos/$distribution/x86_64/cuda-$distribution.pin
$ sudo mv cuda-$distribution.pin /etc/apt/preferences.d/cuda-repository-pin-600
$ sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/$distribution/x86_64/7fa2af80.pub
$ echo "deb http://developer.download.nvidia.com/compute/cuda/repos/$distribution/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list
$ sudo apt-get update
$ sudo apt-get -y install cuda-drivers

参考:https://docs.nvidia.com/datacenter/tesla/tesla-installation-notes/index.html

NVIDIAコンテナツールキットをインストールする

$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
   && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \
   && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
$ sudo apt-get update
$ sudo apt-get install -y nvidia-docker2
$ sudo systemctl restart docker

Tensorflow使う

# bash
docker run --gpus all -it tensorflow/tensorflow:latest-gpu bash

# python適当に起動
docker run --gpus all -it --rm tensorflow/tensorflow:latest-gpu python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

# Jupyter使う
docker pull tensorflow/tensorflow:latest-gpu-jupyter
docker run -it -p 8888:8888 tensorflow/tensorflow:latest-gpu-jupyter

気が向いたら

更新します

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?