私的AI研究会 > ProjectEnv5
AI開発プロジェクト実行に必要な環境を新規作成する手順(最新版)
「NVIDIA cuda GPU」搭載のノートパソコンでローカルマシン上で 生成AI の動作する環境構築の手順
MSI Laptop Cyborg 14 A13V
> nvidia-smi Tue Feb 25 15:42:08 2025 +-----------------------------------------------------------------------------------------+ | NVIDIA-SMI 572.16 Driver Version: 572.16 CUDA Version: 12.8 | |-----------------------------------------+------------------------+----------------------+ | GPU Name Driver-Model | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |=========================================+========================+======================| | 0 NVIDIA GeForce RTX 4060 ... WDDM | 00000000:01:00.0 Off | N/A | | N/A 41C P3 590W / 45W | 0MiB / 8188MiB | 0% Default | | | | N/A | +-----------------------------------------+------------------------+----------------------+ +-----------------------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=========================================================================================| | No running processes found | +-----------------------------------------------------------------------------------------+Graphic board: NVIDIA GeForce RTX 4060
> nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2025 NVIDIA Corporation Built on Wed_Jan_15_19:38:46_Pacific_Standard_Time_2025 Cuda compilation tools, release 12.8, V12.8.61 Build cuda_12.8.r12.8/compiler.35404655_0
(base) echo $env:PYTHONPATH C:\anaconda_win\workspace_py37\mylib;C:\anaconda_win\workspace\lib;C:\anaconda_win\workspace_2\mylib2
%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> = ユーザー名 C: = anaconda_winを配置したドライブ
%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' ; Set-Location 'c:\anaconda_win' "
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
$profile・プロファイルが存在しなければ作成
new-item -path $profile -itemtype file -force※「Microsoft.PowerShell_profile.ps1」という空のファイルが作成される
# PowerShell 動作確認 echo 'Windows PowerShell' Get-Host # 'which' command function which($cmdname) { Get-Command $cmdname | Select-Object -ExpandProperty Definition }
Windows PowerShell Name : ConsoleHost Version : 5.1.26100.2161 InstanceId : fa7d125e-1474-4b7e-882e-67432972f725 UI : System.Management.Automation.Internal.Host.InternalHostUserInterface CurrentCulture : ja-JP CurrentUICulture : ja-JP PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy DebuggerEnabled : True IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces.LocalRunspace (base) PS C:\anaconda_win>
(base) PS > which ls Get-ChildItem (base) PS > which python C:\Users\izuts\anaconda3\python.exe
> git config --global user.name izuts > git config --global user.email izutsum@venus.dti.ne.jp > ssh-keygen Generating public/private rsa key pair. : デフォルトで問題ないので何も入力せずにEnterを押す
> git --version git version 2.43.0.windows.1
> cd C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build > vcvarsall.bat x64 ********************************************************************** ** Visual Studio 2022 Developer Command Prompt v17.13.1 ** Copyright (c) 2022 Microsoft Corporation ********************************************************************** [vcvarsall.bat] Environment initialized for: 'x64'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64
> cd C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build > nmake Microsoft(R) Program Maintenance Utility Version 14.43.34808.0 Copyright (C) Microsoft Corporation. All rights reserved. NMAKE : fatal error U1064: MAKEFILE が見つかりません、またターゲットが指定されていません。 Stop.
project_mylib ├─workspace │ └─lib │ └─images ├─workspace_2 │ └─mylib2 │ ├─mylib_test │ └─result └─workspace_py37 └─mylib └─mylib_test・解凍してできる「project_mylib/」フォルダ内を「anaconda_win/」フォルダの下に上書きコピーする
(base) conda create -n py38_learn python=3.8 -y (base) conda info -e
(base) conda activate py38_learn
(py38_learn) pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 ← GPU の場合 (2024.09.01)
(py38_learn) conda install ffmpeg ffmpeg-python pyaudio dlib -c conda-forge -y
(py38_learn) cd /anaconda_win/workspace_2 (py38_learn) pip install -r requirements3.txt
(py38_learn) pip install imageio[ffmpeg]
(py_learn) python -V Python 3.8.19 (py_learn) python -c 'import torch;print(torch.__version__)' 2.4.0+cu124 (py_learn) python -c 'import torch;print(torch.zeros(1).cuda())' tensor([0.], device='cuda:0')
(py_learn) ffmpeg -h
(py38_learn) python my_videotool.py 0・ウインドウ表示後クローズボタンを押してしばらくすると終了し次のファイルが生成される
Saving mpeg file → 'test_anim.mp4' Saving gif file → 'test_anim.gif'