Windows install from source failing

I am trying to automate builds of python from source on all platforms with cmake. I have Linux and macOS working. I am using bash as the terminal on all platfforms (on Windows, through Msys2 after calling vcvars32.bat on MSVC2019).

Windows is giving me a headache and I cannot find documentation for it. I am able to build python on Windows with no problems using PCbuild/build.bat. However, I don’t know how to install it. I am running the following command for installing:

python.bat -m ensurepip && python.bat -m pip install . --prefix ${CMAKE_INSTALL_PREFIX}

and I get this error:


Running Release|x64 interpreter...
Looking in links: c:\Users\User-PC\AppData\Local\Temp\tmp38gznv73
Requirement already satisfied: setuptools in d:\code\applications\mrv2\build-msys-amd64\release\python-prefix\src\python\lib\site-packages (63.2.0)
Requirement already satisfied: pip in d:\code\applications\mrv2\build-msys-amd64\release\python-prefix\src\python\lib\site-packages (23.0.1)
Running Release|x64 interpreter...
Processing d:\code\applications\mrv2\build-msys-amd64\release\python-prefix\src\python
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  error: subprocess-exited-with-error

  python setup.py egg_info did not run successfully.
  exit code: 1

  [10 lines of output]
  Traceback (most recent call last):
    File "<string>", line 2, in <module>
    File "<pip-setuptools-caller>", line 34, in <module>
    File "D:\code\applications\mrv2\BUILD-Msys-amd64\Release\Python-prefix\src\Python\setup.py", line 2758, in <module>
      main()
    File "D:\code\applications\mrv2\BUILD-Msys-amd64\Release\Python-prefix\src\Python\setup.py", line 2714, in main
      set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
    File "D:\code\applications\mrv2\BUILD-Msys-amd64\Release\Python-prefix\src\Python\setup.py", line 134, in set_compiler_flags
      sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
  TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
  [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

Encountered error while generating package metadata.

See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Build the installer:

Even for local use you might want to sign the binaries (i.e. /p:SigningCertificate=) to help with malware detection. You can create a self-signed certificate using PowerShell’s New-SelfSignedCertificate and Export-Certificate.

Thanks for the reply. Unfortunately, building the installer is not an option. I am trying to automate the builds with cmake, as I have a complex program full of C++ dependencies. I can automate the build process with:

PCbuild/build.bar

which works great, exacept it is missing an install. To make it more clear, I am trying to emulate the:

make
make install

process of Unix systems. But I am missing the install step. As a work-around I built a shell script that copies all the elments from the compiled staging area to the layout of the binary distributions, but I am afraid that could prove unmaintainable if Python changes its layout.

You could use the layout package. For example:

python.bat PC/layout --precompile --preset-default --copy "${CMAKE_INSTALL_PREFIX}"

This copies files to the destination directory using the default layout and precompiles the standard library files in “Lib”.

Thank you!!! That was perfect. Just what I needed.

Thanks to Steve Dower, the author of the layout package.