HoudiniのPythonにモジュールを追加する方法

## HoudiniのPython(2系)にモジュールを追加する方法

[Houdiniで最初から使えるモジュール](https://qiita.com/ijiVFX/items/0bee7d879863089a4284)の中に画像処理などでよく使うOpenCVなどはない。
![image001.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/153910/8f4ddaa2-3a7e-ff46-ba4b-bf99b02afcfe.png)

この様に「その様なモジュールは無い」というエラーが出る。
そこでHoudiniのPythonにOpenCVのモジュールを追加する方法を紹介する。

まず **pip** をインストールする
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/153910/51cec455-3f39-1cdd-348a-7f5a0733546e.png)
**Side Effects Software** の **Command Line Tools** を管理者権限で実行

[get-pip.py](https://bootstrap.pypa.io/pip/2.7/get-pip.py) を落としてきて
D:\直下などに保存したとする。

``` python.exe D:\get-pip.py ```

と入力すると

```
C:\Program Files\Side Effects Software\Houdini 18.5.514\python27>python.exe D:\get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting pip<21.0
  Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
     |################################| 1.5 MB 6.8 MB/s
Collecting wheel
  Downloading wheel-0.36.2-py2.py3-none-any.whl (35 kB)
Installing collected packages: pip, wheel
  WARNING: The scripts pip.exe, pip2.7.exe and pip2.exe are installed in 'C:\Program Files\Side Effects Software\Houdini 18.5.514\python27\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script wheel.exe is installed in 'C:\Program Files\Side Effects Software\Houdini 18.5.514\python27\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-20.3.4 wheel-0.36.2

C:\Program Files\Side Effects Software\Houdini 18.5.514\python27>

```

実際の画面はこの様になる
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/153910/3be75720-32d0-a501-4bed-97522aed503b.png)

これで **pip** がインストール出来た。
**pip** のインストールは一度で良い。

次にインストールしたいモジュールをインストールする。
例えばOpenCVなどをインストールしたい場合


``` python.exe -m pip install opencv-contrib-python ```

とすると

```
C:\Program Files\Side Effects Software\Houdini 18.5.514\python27>python.exe -m pip install opencv-contrib-python
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting opencv-contrib-python
  Downloading opencv_contrib_python-4.2.0.32-cp27-cp27m-win_amd64.whl (39.5 MB)
     |################################| 39.5 MB 8.5 MB/s
Requirement already satisfied: numpy>=1.11.1 in c:\program files\side effects software\houdini 18.5.514\python27\lib\site-packages (from opencv-contrib-python) (1.14.6)
Installing collected packages: opencv-contrib-python
Successfully installed opencv-contrib-python-4.2.0.32

C:\Program Files\Side Effects Software\Houdini 18.5.514\python27>

```

この様に表示されcv2モジュールがHoudiniのPythonの中から呼び出すことが出来る様になった。
実際に動作を確認してみると

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/153910/3869da14-015b-2e05-1c11-b633610bc5e2.png)

エラーが起こらなくなったのが分かる。