10
6

More than 5 years have passed since last update.

Check! Windowsで、BLEでmicrobitを操作できる npmパッケージ `bbc-microbit` をインストールする

Last updated at Posted at 2018-02-10

こんにちは、 @dz_ こと大平かづみです。

Prologue - はじめに

Node-RED から Bluetooth 経由で microbit を操作できるときいて、Windows で試そうとしたところ、必要な bbc-microbit パッケージのインストールでつまづいたので、メモを残します。

Windows に限らず、他の OS でもビルド環境が必要のようなので、同様にエラーが発生する方は 原因と対処 が参考になると思います。

20180123_232248374_iOS.jpg

試行環境の補足

使用機は Windows 10 (Surface Pro 4) です。

エラー内容

bbc-microbit をインストールすると、以下のように node-gyp のリビルドでエラーになります。

※ Node-RED で使う前提なので、 C:\Users\<ユーザー名>\.node-rednpm install を実行しています。

npm install bbc-microbit
> usb@1.3.1 install C:\Users\<ユーザー名>\.node-red\node_modules\usb
> node-pre-gyp install --fallback-to-build

[usb] Success: "C:\Users\<ユーザー名>\.node-red\node_modules\usb\src\binding\usb_bindings.node" is installed via remote

> bluetooth-hci-socket@0.5.1 install C:\Users\<ユーザー名>\.node-red\node_modules\bluetooth-hci-socket
> node-gyp rebuild


C:\Users\<ユーザー名>\.node-red\node_modules\bluetooth-hci-socket>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "C:\Python36\python.EXE", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:483:19)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:508:16)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\<ユーザー名>\.node-red\node_modules\bluetooth-hci-socket
gyp ERR! node -v v8.9.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN node-red-project@0.0.1 No repository field.
npm WARN node-red-project@0.0.1 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: xpc-connection@0.1.4 (node_modules\xpc-connection):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for xpc-connection@0.1.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: bluetooth-hci-socket@0.5.1 (node_modules\bluetooth-hci-socket):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: bluetooth-hci-socket@0.5.1 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ bbc-microbit@0.2.0
added 6 packages in 12.503s

この状態だと、 bbc-microbit はインストールされるんですが、 bluetooth-hci-socket がインストールされてないので、利用しようとすると以下のようにエラーが発生します。

Error: Cannot find module 'bluetooth-hci-socket'

原因と対処

この bbc-microbit は、 以下のように node-gyp パッケージに依存しており、このパッケージは Python 2.7 を含むビルド環境を必要とします。Python 3系はサポートされていません。

bbc-microbit > noble > node-bluetooth-hci-socket > node-gyp

Windows においては、On Windows - nodejs/node-gyp の要件を満たす必要があります。

結構依存が多くて、手動でインストールするか、 windows-build-tools を利用して一括でインストールする方法が挙げられています。

windows-build-tools を利用する場合は、管理者権限で PowerShell を立ち上げ、以下を実行します。Python 2.7 と Visual Studio Build Tools がインストールされるようです。

windows-build-toolsのインストール
PS C:\WINDOWS\system32> npm install --global --production windows-build-tools
windows-build-toolsのインストール結果
> windows-build-tools@1.4.2 postinstall C:\Users\<ユーザー名>\AppData\Roaming\npm\node_modules\windows-build-tools
> node ./lib/index.js

Downloading BuildTools_Full.exe
Downloading python-2.7.14.amd64.msi
[>                                            ] 0.0% (0 B/s)
Downloaded python-2.7.14.amd64.msi. Saved to C:\Users\<ユーザー名>\.windows-build-tools\python-2.7.14.amd64.msi.
Starting installation...
Launched installers, now waiting for them to finish.
This will likely take some time - please be patient!
Waiting for installers... |Successfully installed Python 2.7
Waiting for installers... |Successfully installed Visual Studio Build Tools.
+ windows-build-tools@1.4.2
added 128 packages in 253.664s

この後、もう一度 bbc-microbit のインストールを行うと、このように無事インストールされました。

npm install bbc-microbit
> usb@1.3.1 install C:\Users\<ユーザー名>\.node-red\node_modules\usb
> node-pre-gyp install --fallback-to-build

[usb] Success: "C:\Users\<ユーザー名>\.node-red\node_modules\usb\src\binding\usb_bindings.node" is installed via remote

> bluetooth-hci-socket@0.5.1 install C:\Users\<ユーザー名>\.node-red\node_modules\bluetooth-hci-socket
> node-gyp rebuild


C:\Users\<ユーザー名>\.node-red\node_modules\bluetooth-hci-socket>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  win_delay_load_hook.cc
  Generating code
  Finished generating code
  binding.vcxproj -> C:\Users\<ユーザー名>\.node-red\node_modules\bluetooth-hci-socket\build\Release\\binding.node
  binding.vcxproj -> C:\Users\<ユーザー名>\.node-red\node_modules\bluetooth-hci-socket\build\Release\binding.pdb (Full
   PDB)
npm WARN node-red-project@0.0.1 No repository field.
npm WARN node-red-project@0.0.1 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: xpc-connection@0.1.4 (node_modules\xpc-connection):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for xpc-connection@0.1.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ bbc-microbit@0.2.0
added 79 packages in 26.041s

Epilogue - おわりに

この後、無事にインストールできて Node-RED も動きました。ただ、残念なことに
Bluetooth での接続には失敗してみました。

もしかしたら、先日マシンを落下し破損したせいで、内部的にもどこかおかしいのかもしれません(画面バリバリ)。ハードウェア交換した後でまた試してみます。

10
6
2

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
10
6