6
2

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 1 year has passed since last update.

Mac DockerにPython環境を構築する

Last updated at Posted at 2022-10-01

読む前に

自分は勉強中のエンジニアのため間違いが散見される場合があります
ご了承の上お読みください
環境:MacBook Air M1, vscode

Background

oss開発に参加したいと考えたため

tqdm
pytorchの待ち時間可視化のためによく使わせてもらっている
初めてのossなので手頃そうかなと
興味の湧いたプルリク
いやchromeの恐竜ちゃんみたいでcoolすぎでしょ
自分も作りたいと思った

いざコードを見てみると。。。

environment.yml
# development environment
name: tqdm
channels:
- conda-forge
- defaults
dependencies:
# base
- python=3
...

anacondaの開発環境がつらつら書かれていた
自分は普段Python3.9を使っているので環境も汚したくないし、Dockerの勉強にもなるので仮想環境を立ち上げることにした

Docker install

こちらの記事を参考にした

できなかったのでこちらで再度インストール

Docker build

ubuntuで構築したい場合
https://qiita.com/kuboko-jp/items/6388c186e16028d3e699
https://qiita.com/silloi/items/739699337b9bf4883b3e

こちらを参考にDockerfileを記述

docker-compose.yml
version: '3'
services:
  anaconda:
    build:
      context: .
      dockerfile: 'Dockerfile'
    container_name: 'container'
    working_dir: '/tqdm'
    tty: true
    volumes:
      - ./tqdm:/tqdm

tqdmにdependenciesがあったのでコピーして環境構築
minicondaだとモジュールが充分にインストールできなかった

.Dockerfile
FROM continuumio/anaconda3
COPY tqdm/environment.yml environment.yml
RUN conda env create -f environment.yml

docker system prune -a

なんかうまくいかない時はこれで全部消せます

prod-tqdm % docker compose up -d                       
2022/10/01 23:39:55 INFO: [core] original dial target is: "unix:///run/buildkit/buildkitd.sock"
2022/10/01 23:39:55 INFO: [core] parsed dial target is: {Scheme:unix Authority: Endpoint:run/buildkit/buildkitd.sock URL:{Scheme:unix Opaque: User: Host: Path:/run/buildkit/buildkitd.sock RawPath: ForceQuery:false RawQuery: Fragment: RawFragment:}}
2022/10/01 23:39:55 INFO: [core] Channel authority set to "localhost"
2022/10/01 23:39:55 INFO: [core] ccResolverWrapper: sending update to cc: {[{/run/buildkit/buildkitd.sock  0x140004c0b08 <nil> 0 <nil>}] <nil> <nil>}
2022/10/01 23:39:55 INFO: [core] ClientConn switching balancer to "pick_first"
2022/10/01 23:39:55 INFO: [core] Channel switches to new LB policy "pick_first"
2022/10/01 23:39:55 INFO: [core] Subchannel Connectivity change to CONNECTING
2022/10/01 23:39:55 INFO: [core] Subchannel picks a new address "/run/buildkit/buildkitd.sock" to connect
2022/10/01 23:39:55 INFO: [core] blockingPicker: the picked transport is not ready, loop back to repick
2022/10/01 23:39:55 INFO: [core] pickfirstBalancer: UpdateSubConnState: 0x1400040c730, {CONNECTING <nil>}
2022/10/01 23:39:55 INFO: [core] Channel Connectivity change to CONNECTING
2022/10/01 23:39:55 INFO: [core] Subchannel Connectivity change to READY
2022/10/01 23:39:55 INFO: [core] pickfirstBalancer: UpdateSubConnState: 0x1400040c730, {READY <nil>}
2022/10/01 23:39:55 INFO: [core] Channel Connectivity change to READY
[+] Building 291.1s (8/8) FINISHED
(base) root@a0af6dae6828:/tqdm# conda list
# packages in environment at /opt/conda:
#
# Name                    Version                   Build  Channel
.....
numpy                     1.21.5
.....

ちゃんと入ってる

こちらの記事を参考にvscodeでcontainerに入る

Hello World

ここを参考に動作確認

test.py
from tqdm.notebook import tqdm_notebook

t = tqdm_notebook(total=5)
t.update(1)

for i in range(5):
    print(t)
    t.update(1)

スクリーンショット 2022-10-02 11.21.35.png

いい感じである

次回はコードに変更を加えていきたい

6
2
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
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?