0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PowerShellにおいて、Python venvの仮想環境化でblenderコマンドを使う

Last updated at Posted at 2024-10-14

この記事について(備忘録)

https://github.com/hbertiche/NeuralClothSim
上記の論文を実装する際に

sh
$ blender --python get_body_model.py
$ blender --python get_sequence.py

というblenderのコードを入力するところがあります。
Windowsの初期設定ではblenderのパスが通っていないため、大体の環境ではおそらくエラーが発生します。仮想環境に入らない状態でblenderにパスを通すのと、仮想環境下でblenderにパスを通すのではやり方が違うため両方紹介します。

目次

環境

Windows11
Python 3.13.0
PowerShell

仮想環境に入らない状態でblenderのパスを通す時

1. Blenderのインストールディレクトリを確認

通常、Blenderは以下の場所にインストールされています:

C:\Program Files\Blender Foundation\Blender [バージョン]

例:C:\Program Files\Blender Foundation\Blender 3.0

このパスをコピーしておきます。

2. 環境変数の設定

(著者のWindows11は英語なのでスクショに記載されているのは英語になります)

  • Windowsアイコンを右クリックし、「System」を選択

  • 「Advanced system settings」を選択System Propertiesが開く

  • System Propertiesの「Advanced」タブに移動

  • 「Environment Variables」をクリック

  • 下のスクショのようにPATHを選んで「OK」をクリック

  • Screenshot 2024-10-14 143023.png

  • 「Edit environment variable」の画面で、「New」をクリックし、先程コピーしたblenderのパスを入力。この時点で下図のようになっているはず
    Screenshot 2024-10-14 143307.png

  • 「OK」をクリックして、すべてのダイアログを閉じます。

3. 動作確認

コマンドプロンプトを再起動し(おそらく再起動しないと反映されない可能性がある。)、以下のコマンドを実行してBlenderのバージョン情報が表示されるか確認します:

sh
blender --version

下記のメッセージが表示されれば成功。

sh
TBBmalloc: skip allocation functions replacement in ucrtbase.dll: unknown prologue for function _msize
Blender 4.2.2 LTS
        build date: 2024-09-24
        build time: 01:17:42
        build commit date: 2024-09-23
        build commit time: 12:18
        build hash: c03d7d98a413
        build branch: blender-v4.2-release
        build platform: Windows
        build type: Release
        build c flags: /W3 /w34062 /w34100 /w34115 /w34189 /w35038 /wd4018 /wd4146 /wd4065 /wd4127 /wd4181 /wd4200 /wd4244 /wd4267 /wd4305 /wd4800 /wd4828 /wd4996 /wd4661 /wd4848 /we4013 /we4133 /we4431 /we4033 /DWIN32 /D_WINDOWS /W3 /nologo /J /Gd /MP /bigobj /Zc:inline  -openmp
        build c++ flags: /W3 /w34062 /w34100 /w34115 /w34189 /w35038 /wd4018 /wd4146 /wd4065 /wd4127 /wd4181 /wd4200 /wd4244 /wd4267 /wd4305 /wd4800 /wd4828 /wd4996 /wd4661 /wd4848 /we4013 /we4133 /we4431 /we4033 /DWIN32 /D_WINDOWS /W3  /EHsc /nologo /J /Gd /MP /EHsc /bigobj /permissive- /Zc:__cplusplus /Zc:inline  -openmp
        build link flags: /MACHINE:X64  /SUBSYSTEM:CONSOLE /STACK:2097152 /ignore:4049 /ignore:4217 /ignore:4221
        build system: CMake

venvの仮想環境下でblenderのパスを通す時

何もパスを通していない状態でblender --versionのコマンドを使うとおそらく以下のエラーが出現します。

sh
blender : The term 'blender' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:1
+ blender --version
+ ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (blender:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

1. Activate.ps1の編集

テキストエディタ(メモ帳、Visual Studio Codeなど)でActivate.ps1を開きます。
Activate.ps1のどこかに以下のようにPATHが通っているはずです。

Activate.ps1
# Add the venv to the PATH
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"

以下のようにパスを追加します。

Activate.ps1
# Add the venv to the PATH
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"

# Add Blender to the PATH
$env:Path += ";C:\Program Files\Blender Foundation\Blender 4.2\bin\"

2. PowerShellの再起動

仮想環境からdeactivateして、PowerShellを再起動してください(重要)

3. 動作確認

コマンドプロンプトを再起動し(おそらく再起動しないと反映されない可能性がある。)、以下のコマンドを実行してBlenderのバージョン情報が表示されるか確認します:

sh
blender --version

下記のメッセージが表示されれば成功。

sh
TBBmalloc: skip allocation functions replacement in ucrtbase.dll: unknown prologue for function _msize
Blender 4.2.2 LTS
        build date: 2024-09-24
        build time: 01:17:42
        build commit date: 2024-09-23
        build commit time: 12:18
        build hash: c03d7d98a413
        build branch: blender-v4.2-release
        build platform: Windows
        build type: Release
        build c flags: /W3 /w34062 /w34100 /w34115 /w34189 /w35038 /wd4018 /wd4146 /wd4065 /wd4127 /wd4181 /wd4200 /wd4244 /wd4267 /wd4305 /wd4800 /wd4828 /wd4996 /wd4661 /wd4848 /we4013 /we4133 /we4431 /we4033 /DWIN32 /D_WINDOWS /W3 /nologo /J /Gd /MP /bigobj /Zc:inline  -openmp
        build c++ flags: /W3 /w34062 /w34100 /w34115 /w34189 /w35038 /wd4018 /wd4146 /wd4065 /wd4127 /wd4181 /wd4200 /wd4244 /wd4267 /wd4305 /wd4800 /wd4828 /wd4996 /wd4661 /wd4848 /we4013 /we4133 /we4431 /we4033 /DWIN32 /D_WINDOWS /W3  /EHsc /nologo /J /Gd /MP /EHsc /bigobj /permissive- /Zc:__cplusplus /Zc:inline  -openmp
        build link flags: /MACHINE:X64  /SUBSYSTEM:CONSOLE /STACK:2097152 /ignore:4049 /ignore:4217 /ignore:4221
        build system: CMake
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?