如何使用node-gyp构建python?

我已经看到the official tutorialthis展示了如何从源代码构建python并使用Visual Studio等对其进行编辑,但是我如何使用node-gyp构建它以使用它作为节点中的本机应用程序?

例如,在本教程中,他们告诉您download the source code,然后在Windows中键入该目录:

"PCbuild/build.bat"   

然后通常会构建Visual Studio解决方案和python等,但是现在我该如何使用node-gyp做到这一点?通常,要包括要使用node-gyp构建的外部依赖项,只需将它们包括在binding.gyp文件中。对于python,我首先在C:/ Python382中安装了64位(后来又增加了32位,与下面的错误相同)python,然后将该文件夹复制到我的C ++应用程序的另一个文件夹中,并设置binding.gyp文件到此(获取包含和库):

{
  "targets": [
    {
        "target_name": "addon","sources": [ 
            "<!@(node -p \"var fs=require('fs'),path=require('path'),walk=function(r){let t,e=[],n=null;try{t=fs.readdirSync(r)}catch(r){n=r.toString()}if(n)return n;var a=0;return function n(){var i=t[a++];if(!i)return e;let u=path.resolve(r,i);i=r+'/'+i;let c=fs.statSync(u);if(c&&c.isDirectory()){let r=walk(i);return e=e.concat(r),n()}return e.push(i),n()}()};walk('./sources').join(' ');\")"
        ],"libraries":[
            "C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/libs/python38.lib","C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/libs/python3.lib","C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/libs/_tkinter.lib"
        ],"include_dirs": [
            "C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/include"
        ],"dll_files": [
            "C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/python38.dll"
        ]
    }
  ]
}

和另一个来源我的hello.cc文件仅包含Python.h。当我使用node-gyp buildnode-gyp rebuild运行此构建时,它实际上构建良好,没有任何错误,但是当我将文件addon.node复制到我的实际nodeJS服务器时,该服务器仅包含一个第var addon = require("./addon")行,我在CMD中得到以下错误输出(但是,如果在我的.cc源文件中不包含Python.h,它可以正常工作且没有错误):

internal/modules/cjs/loader.js:1197
  return process.dlopen(module,path.toNamespacedPath(filename));
                 ^

Error: \\?\C:\Users\Coby\Documents\aa\atzmus\testServer\addon.node is not a valid Win32 application.
\\?\C:\Users\Coby\Documents\aa\atzmus\testServer\addon.node
←[90m    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1197
:18)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:983:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:891:14)←[39m
←[90m    at Module.require (internal/modules/cjs/loader.js:1023:19)←[39m
←[90m    at require (internal/modules/cjs/helpers.js:72:18)←[39m
    at Object.<anonymous> (C:\Users\Coby\Documents\aa\atzmus\testServer\oy.js:2:
9)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1128:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:1
0)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:983:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:891:14)←[39m

主要部分似乎是:

addon.node is not a valid Win32 application.

我尝试使用python在64位Windows上执行此操作,对于32位Windows,我的系统使用64位,我的nodeJS安装是64位,但是我也尝试使用32位note进行尝试;我不知道如何确切地解决此问题,或者是否还有另一种完全用node-gyp构建python的方法?

如此:

在Windows中需要执行哪些步骤才能通过node-gyp构建python,以便能够在不依赖子进程的情况下将Python与nodejs一起使用?

xuzhihua131792 回答:如何使用node-gyp构建python?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2569854.html

大家都在问