2

我正在使用Electronserialport开发一个项目。

串行端口库不会自动工作。在 Readme.md 中搜索,我发现需要使用electron-rebuild库为 NodeJS 版本的电子重新编译库。(在 package.json 中插入这个脚本:)"install": "electron-rebuild"

电子重建需要在计算机中安装 python,所以我通过windows-build-tools安装。(全局安装)

所以现在当我运行命令时,npm install我收到了这个错误:

× Rebuild Failed
An unhandled error occurred inside electron-rebuild
gyp ERR! configure error
gyp ERR! stack Error: spawn C:\Users\Leonardo Guimar�es\.windows-build-tools\python27\python.exe ENOENT
gyp ERR! stack     at exports._errnoException (util.js:1022:11)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
gyp ERR! stack     at onErrorNT (internal/child_process.js:359:16)
gyp ERR! stack     at _combinedTickCallback (internal/process/next_tick.js:74:11)
gyp ERR! stack     at process._tickCallback (internal/process/next_tick.js:98:9)
gyp ERR! System Windows_NT 10.0.14393
gyp ERR! command "D:\\nodejs\\node.exe" "D:\\ElectronWorkspace\\PATH_TO_App\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=1.5.0" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source" "--module_name=serialport" "--module_path=D:\\ElectronWorkspace\\PATH_TO_App\\node_modules\\serialport\\build\\Release" "--host=https://github.com/EmergingTechnologyAdvisors/node-serialport/releases/download/4.0.7"
gyp ERR! cwd D:\ElectronWorkspace\PATH_TO_App\node_modules\serialport
gyp ERR! node -v v6.9.4
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok

Failed with exit code: 1

Error: gyp ERR! configure error
gyp ERR! stack Error: spawn C:\Users\Leonardo Guimar�es\.windows-build-tools\python27\python.exe ENOENT
gyp ERR! stack     at exports._errnoException (util.js:1022:11)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
gyp ERR! stack     at onErrorNT (internal/child_process.js:359:16)
gyp ERR! stack     at _combinedTickCallback (internal/process/next_tick.js:74:11)
gyp ERR! stack     at process._tickCallback (internal/process/next_tick.js:98:9)
gyp ERR! System Windows_NT 10.0.14393
gyp ERR! command "D:\\nodejs\\node.exe" "D:\\ElectronWorkspace\\PATH_TO_App\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=1.5.0" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source" "--module_name=serialport" "--module_path=D:\\ElectronWorkspace\\PATH_TO_App\\node_modules\\serialport\\build\\Release" "--host=https://github.com/EmergingTechnologyAdvisors/node-serialport/releases/download/4.0.7"
gyp ERR! cwd D:\ElectronWorkspace\PATH_TO_App\node_modules\serialport
gyp ERR! node -v v6.9.4
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok

Failed with exit code: 1
    at SafeSubscriber.obs.subscribe.e [as _error] (D:\ElectronWorkspace\PATH_TO_App\node_modules\spawn-rx\lib\index.js:311:43)
    at SafeSubscriber.__tryOrUnsub (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:223:16)
    at SafeSubscriber.error (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:184:26)
    at Subscriber._error (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:128:26)
    at Subscriber.error (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:102:18)
    at MapSubscriber.Subscriber._error (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:128:26)
    at MapSubscriber.Subscriber.error (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:102:18)
    at SafeSubscriber.pipesClosed.subscribe [as _next] (D:\ElectronWorkspace\PATH_TO_App\node_modules\spawn-rx\lib\index.js:284:42)
    at SafeSubscriber.__tryOrSetError (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:232:16)
    at SafeSubscriber.next (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:174:27)
    at Subscriber._next (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:125:26)
    at Subscriber.next (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:89:18)
    at ReduceSubscriber._complete (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\operator\reduce.js:116:30)
    at ReduceSubscriber.Subscriber.complete (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:114:18)
    at MergeAllSubscriber._complete (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\operator\mergeAll.js:94:30)
    at MergeAllSubscriber.Subscriber.complete (D:\ElectronWorkspace\PATH_TO_App\node_modules\rxjs\Subscriber.js:114:18)

我怎样才能编译这个库?提前致谢!

4

3 回答 3

3

安装windows构建工具

npm install --global --production windows-build-tools 

或者

 npm --add-python-to-path='true' --debug install --global windows-build-tools

然后设置路径变量

setx PYTHON "%USERPROFILE%\.windows-build-tools/python27/python.exe"

set PYTHON

set PYTHON 可帮助您检查其设置是否正确。

在您的项目文件中全局安装电子重建是不够的

npm install -g electron-prebuilt  

npm install --save serialport

我们必须重建串行端口才能使用电子。为此,我们需要安装电子重建:

npm install --save-dev electron-rebuild 

最后一步是再次在应用程序的根目录中运行 electron-rebuild:

 ./node_modules/.bin/electron-rebuild
于 2019-03-21T15:32:48.113 回答
1

serialport按照这些步骤,我设法在 Windows 10 x64 上为 Electron 1.4.14 编译。这在一周前有效,所以我不太确定在此期间是否发生了变化。

我首先需要 Windows 10 SDK、C++ 通用工具(包含在 Visual Studio Community 2015 中)electron-rebuild。Python 2.x 也是必需的。然后我安装electron-rebuildserialport使用了 npm(使用 --save-dev 选项)。

然后我删除了node_modules/serialport/build/Release/*我的应用程序文件夹node_modules/.bin中的文件,最后转到项目中的文件夹并运行命令:

electron-rebuild -v 1.4.14 -e node_modules/electron-prebuilt -f我删除的文件再次出现,但为实际版本重建。请务必指定您正在使用的正确 Electron 版本。

于 2017-02-02T10:40:32.467 回答
0

这对我有用。

npm config set python /path/to/executable/python2.7

然后尝试。

npm install
于 2018-05-04T16:30:05.833 回答