title: how to build python with node-gyp?
body: <p>I've seen <a href="https://devguide.python.org/setup/" rel="nofollow noreferrer">the official tutorial</a> as well as <a href="https://cpython-core-tutorial.readthedocs.io/en/latest/build_cpython_windows.html" rel="nofollow noreferrer">this</a> one showing how to build python from source and edit it with visual studio etc., but how do I build it with node-gyp to use it as a native application in node?</p>
  <p>For example, in the tutorial, they tell you to <a href="https://github.com/python/cpython" rel="nofollow noreferrer">download the source code</a>, and then (in windows) type in that directory:</p>
  <pre><code>&quot;PCbuild/build.bat&quot;   
  </code></pre>
  <p>and then that builds the Visual Studio solution and python in general etc., but now how do I do that with node-gyp? In general, to include external dependencies to build with node-gyp, you just include them in the binding.gyp file. For python, I first installed 64 bit (and later 32 bit, same error as below) <a href="https://www.python.org/downloads/windows/" rel="nofollow noreferrer">python</a> to C:/Python382, then I copied that folder to my another folder in my C++ application, and set the binding.gyp file to this (to get the include and libs):</p>
  <pre><code>{
    &quot;targets&quot;: [
      {
          &quot;target_name&quot;: &quot;addon&quot;,
          &quot;sources&quot;: [ 
              &quot;&lt;!@(node -p \&quot;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&amp;&amp;c.isDirectory()){let r=walk(i);return e=e.concat(r),n()}return e.push(i),n()}()};walk('./sources').join(' ');\&quot;)&quot;
          ],
          &quot;libraries&quot;:[
              &quot;C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/libs/python38.lib&quot;,
              &quot;C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/libs/python3.lib&quot;,
              &quot;C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/libs/_tkinter.lib&quot;
          ],
          &quot;include_dirs&quot;: [
              &quot;C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/include&quot;
          ],
          &quot;dll_files&quot;: [
              &quot;C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/python38.dll&quot;
          ]
      }
    ]
  }
  </code></pre>
  <p>and my hello.cc file, which is the other source, simply includes <code>Python.h</code>. When I run this build using <code>node-gyp build</code> or <code>node-gyp rebuild</code>, it actually builds fine with no errors at all, but then when I copy over the file addon.node to my actual nodeJS server, which simply has the one line <code>var addon = require(&quot;./addon&quot;)</code>, I get the following error output in CMD (however, it works fine with no errors without including Python.h in my .cc source file):</p>
  <pre><code>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.&lt;anonymous&gt; (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
  </code></pre>
  <p>The main part seems to be:</p>
  <blockquote>
  <p><code>addon.node is not a valid Win32 application.</code></p>
  </blockquote>
  <p>I tried doing this with python for 64bit windows, and for 32bit windows, my system in 64 bit, my nodeJS installation is 64 bit, but I also tried it with 32 bit note; I don't know how to fix this exactly, or if there is another way entirely to build python with node-gyp?</p>
  <p>so:</p>
  <p><strong>What steps need to be taken in windows to build  python through node-gyp, to be able to use python natively with nodejs without having to resort to child-process?</strong></p>