Windows 上で AI コンペ向けの開発環境を構築する手順をまとめました。Python / PyTorch / VSCode を中心に、WSL2 での作業を前提としています。
1. WSL2 セットアップ
1.1 WSL2 インストール
-
Windows機能の有効化 管理者権限で PowerShell を開き、以下を実行:
wsl --install -d Ubuntu-22.04 -
WSL2 バージョン確認
wsl -l -v
1.2 必要ツールのインストール 例
WSL初回起動時はUnixユーザー名とパスワード登録がある。 WSL 内で以下を実行:
sudo apt update
sudo apt install -y curl git build-essential unzip wget
1.3 Python 環境管理(uv)
curl -LsSf https://astral.sh/uv/install.sh | sh
2. VSCode セットアップ
2.1 VSCode インストール
公式サイトから Windows 版をインストール:VSCode ダウンロード
2.2 Remote - WSL 拡張
- VSCode の拡張機能からRemote Development (の中に含まれるWSL)をインストール。
- CtrL + Shift + P でコマンドを出してから、
- wsl connect Using Distro
- Ubuntuを選択
2.4 推奨拡張機能
- Python
- Pylance
- Jupyter
- Git Graph
- Docker(必要に応じて)
3. プロジェクト Initialize
uv init
3.1 PyTorch インストール
GPU 対応の場合は CUDA バージョンに合わせて:
$ # With a command-line argument.
$ uv pip install torch --torch-backend=auto
確認:
import torch
print(torch.cuda.is_available())
3.2 データセット配置と I/O
- ディレクトリ作成:
mkdir -p ~/ai_competition/data
cd ~/ai_competition/data
- WSL 内に直接ダウンロード:
curl -O https://example.com/dataset/train.csv
curl -O https://example.com/dataset/test.csv
- 大容量の場合は
wgetが便利:
wget https://example.com/dataset/large_dataset.zip
unzip large_dataset.zip
- Python からの読み込み:
import pandas as pd
train_df = pd.read_csv('~/ai_competition/data/train.csv')
test_df = pd.read_csv('~/ai_competition/data/test.csv')
Kaggle apiを使うと便利
pip install kaggle --upgrade
kaggle competitions {list, files, download, submit, submissions, leaderboard}
kaggle datasets {list, files, download, create, version, init}