1. 概要
Docker や WSL 経由で Ubuntu が使えるならそっちでやろう。
この記事は、何らかの理由で Ubuntu を使えない人のためのものです。
2. 環境
リソース / Package | version |
---|---|
windowsOS | 10 |
WSL | 使わない |
docker | 使わない |
anaconda / miniconda | 使わない |
Visual Studio | 2017 |
pyenv-win | 3.1.1 |
python | 3.7.3 |
swig (swigwin) | 4.0.1 1 |
注意点
python が 3.7.3
という中途半端に古いバージョンになっているのは、「windows上で vcvarsall.bat
を正しく見つけられると確認できた」のが、「python 3.7.3 と VisualStudio 2017 の組合せ」のときだけだったため。
これよりも上のバージョンで動作確認出来たら、本当はそちらを使いたい。
いや、嘘です。それよりも Ubuntu を使いたいです。心の底から。
3. 手順
3-1. Visual Studio 2017 のインストール
注意点
おそらく、Python をインストールする前に VisualStudio をインストールしておく必要がある。
もし先に Python を install してあった場合は、一度 uninstall して、VisualStudio を先に install してから Python (と pip package たち) を入れ直そう。
Visual Studio の必要性
Visual Studio が無いまま swig を使うとこうなることがある。
よくあるエラー。Unable to find vcvarsall.bat
。
> python setup.py build_ext --inplace
running build_ext
building '_pafprocess' extension
swigging pafprocess.i to pafprocess_wrap.cpp
C:\swigwin-4.0.1\swig.exe -python -c++ -o pafprocess_wrap.cpp pafprocess.i
error: Unable to find vcvarsall.bat
VisualStudio 2017 install 方法
以下の記事に従う。
install し終わったら、念のため windows 本体を再起動しておく。
3-2. Install swig
Download and decompress zip
Access SOURCEFORGE and download your necessary version of swigwin.
After downloading the zip file, decompress it and select C:\swigwin-4.0.1
as the destination of decompression.
Please, confirm there is C:\swigwin-4.0.1\swig.exe
.
Add path
You can add a path to windows by following the next website.
Concretely, these images will help you.
At first, do right click
on Start button, and select システム
.
You'll see バージョン情報
.
Then, scroll down the window.
Click システム情報
.
And click システムの詳細設定
on システム
window.
Next, click the button of 環境変数
.
Then, select the Path
in the block of システム環境変数
and click the button of 編集
.
Click the button of 新規
, add C:\swigwin-4.0.1
, and click OK !
At last click OK again !
Confirmation
Then restart
your powershell and check whether swig is installed successfully or not like this.
> swig -version
SWIG Version 4.0.1
Compiled with i686-w64-mingw32-g++ [i686-w64-mingw32]
Configured options: +pcre
Please see http://www.swig.org for reporting bugs and further information
3-3. swig 実行
以下のコマンド実行前に、 pip
で numpy
を install しておく必要があるので注意。
swig の利用方法は人によって全然違うと思うけれど、自分の場合は pytorch_realtime_multi-person_pose_estimation
というリポジトリで swig
を使っているので、以下のように使った。
> python setup.py build_ext --inplace
# もしくは以下のコマンド
# python でダメでも、 python3 なら動くことがある
> python3 setup.py build_ext --inplace
結果は以下の通り。
pafprocess.cpp
c:\users\USERNAME\pytorch_realtime_multi-person_pose_estimation\lib\pafprocess\pafprocess.h(6): warning C4305: '初期化中': 'double' から 'float' へ切り詰めます。
c:\users\USERNAME\pytorch_realtime_multi-person_pose_estimation\lib\pafprocess\pafprocess.h(7): warning C4305: '初期化中': 'double' から 'float' へ切り詰めます。
c:\users\USERNAME\pytorch_realtime_multi-person_pose_estimation\lib\pafprocess\pafprocess.h(10): warning C4305: '初期化中': 'double' から 'float' へ切り詰めます。
pafprocess.cpp(30): warning C4244: '=': 'float' から 'int' への変換です。データが失われる可能性があります。
pafprocess.cpp(31): warning C4244: '=': 'float' から 'int' への変換です。データが失われる可能性があります。
pafprocess.cpp(33): warning C4244: '初期化中': 'float' から 'int' への変換です。データが失われる可能性があります。
pafprocess.cpp(63): warning C4244: '=': 'int' から 'float' への変換です。データが失われる可能性があります。
pafprocess.cpp(64): warning C4244: '=': 'int' から 'float' への変換です。データが失われる可能性があります。
pafprocess.cpp(83): warning C4244: '初期化中': '_Ty' から 'float' への変換です。データが失われる可能性があります。
with
[
_Ty=double
]
pafprocess.cpp(148): warning C4244: '=': 'int' から '_Ty' への変換です。データが失われる可能性があります。
with
[
_Ty=float
]
pafprocess.cpp(169): warning C4244: '=': 'int' から '_Ty' への変換です。データが失われる可能性があります。
with
[
_Ty=float
]
pafprocess.cpp(176): warning C4244: '=': 'int' から '_Ty' への変換です。データが失われる可能性があります。
with
[
_Ty=float
]
pafprocess.cpp(177): warning C4244: '=': 'int' から '_Ty' への変換です。データが失われる可能性があります。
with
[
_Ty=float
]
pafprocess.cpp(188): warning C4267: '初期化中': 'size_t' から 'int' に変換しました。データが失われているかもしれません 。
pafprocess.cpp(197): warning C4267: 'return': 'size_t' から 'int' に変換しました。データが失われているかもしれません。
pafprocess.cpp(201): warning C4244: 'return': '_Ty' から 'int' への変換です。データが失われる可能性があります。
with
[
_Ty=float
]
pafprocess_wrap.cpp
c:\users\USERNAME\pytorch_realtime_multi-person_pose_estimation\lib\pafprocess\pafprocess.h(6): warning C4305: '初期化中': 'double' から 'float' へ切り詰めます。
c:\users\USERNAME\pytorch_realtime_multi-person_pose_estimation\lib\pafprocess\pafprocess.h(7): warning C4305: '初期化中': 'double' から 'float' へ切り詰めます。
c:\users\USERNAME\pytorch_realtime_multi-person_pose_estimation\lib\pafprocess\pafprocess.h(10): warning C4305: '初期化中': 'double' から 'float' へ切り詰めます。
ライブラリ build\temp.win-amd64-cpython-37\Release\_pafprocess.cp37-win_amd64.lib とオブジェクト build\temp.win-amd64-cpython-37\Release\_pafprocess.cp37-win_amd64.exp を作成中
コード生成しています。
コード生成が終了しました。
>
成功。
(ログを見ると微妙に怪しく見えるけれど、これで生成されたコードは確かに役目を果たしてくれた。)
参考サイト
windows path について
Windows への Path の追加方法は MatLab の記事が一番わかりやすかった。
swig について
- swigの公式ドキュメント
- 以下はどれも、あんまり参考にならなかった。。。
-
swig
が4.0.1
である必要性は特になかったが、別の環境で使っていたのが4.0.1
だったのでそれに合わせた。ここをご覧になっている方々がそうする必要があるわけではないが、この記事で動作を確認できているのは4.0.1
のみ。 ↩