Understanding the Ghost Path Issue in MSYS2 UCRT64

When developing digital signal processing (DSP) pipelines using GNU Radio on Windows via MSYS2 UCRT64, you might encounter a frustrating CMake error during flowgraph generation. Specifically, CMake halts with a path like this:

-- User set python executable D:/M/msys64/ucrt64/bin/python3.exe
CMake Error at C:/msys64/ucrt64/lib/cmake/gnuradio/GrPython.cmake:27 (find_package):
  find_package called with invalid argument "."

If you have installed MSYS2 to C:\msys64, you might wonder where this phantom D:/M/ drive comes from. The path is a hardcoded artifact from the automated build farm where the MSYS2 binary package was compiled. When GNU Radio Companion (GRC) invokes CMake in the background to build C++ targets, it relies on exported CMake configurations that point to the build server's original file hierarchy.

While passing -DPYTHON_EXECUTABLE="${MINGW_PREFIX}/bin/python" works for manual terminal builds, it doesn't solve the issue inside GNU Radio Companion. Below are the most effective ways to permanently resolve this conflict.

Method 1: Patching GNU Radio's CMake Configuration (Recommended)

Because the invalid path is embedded directly inside the installed GNU Radio CMake helpers, the cleanest fix is to correct the path inside GrPython.cmake.

  1. Open an MSYS2 UCRT64 terminal or your favorite text editor with administrator permissions.
  2. Locate the file:
    C:\msys64\ucrt64\lib\cmake\gnuradio\GrPython.cmake
  3. Search for references to D:/M/msys64 or the variable setting PYTHON_EXECUTABLE. You will typically see a fallback line configured during the package build:
    set(PYTHON_EXECUTABLE "D:/M/msys64/ucrt64/bin/python3.exe" CACHE FILEPATH ...)
  4. Update this line to reflect your actual installation path or make it dynamic:
    set(PYTHON_EXECUTABLE "C:/msys64/ucrt64/bin/python.exe" CACHE FILEPATH "Python executable" FORCE)
  5. Save the file and regenerate your flowchart inside GNU Radio Companion.

Method 2: Exporting Environment Variables for GRC

GNU Radio Companion passes environment variables to its subshells when generating and compiling flowcharts. You can force CMake to look at your actual Python interpreter by setting standard CMake environment variables before starting GRC.

In your UCRT64 shell, launch GNU Radio Companion with explicit environment overrides:

# Export the correct Python path for CMake
export CMAKE_GENERATOR="Ninja" # Optional, ensures fast compilation
export PYTHON_EXECUTABLE="${MINGW_PREFIX}/bin/python.exe"
export Python3_EXECUTABLE="${MINGW_PREFIX}/bin/python.exe"

# Launch GNU Radio Companion
gnuradio-companion

To make this change permanent across terminal sessions, add the export statements to your ~/.bashrc or ~/.profile inside MSYS2:

echo 'export PYTHON_EXECUTABLE="${MINGW_PREFIX}/bin/python.exe"' >> ~/.bashrc
echo 'export Python3_EXECUTABLE="${MINGW_PREFIX}/bin/python.exe"' >> ~/.bashrc

Method 3: Configure User CMake Flags in GRC Preferences

GNU Radio Companion allows you to pass custom generator options in its configuration file. You can inject the correct parameter into all automated builds:

  1. Open or create the GNU Radio configuration file located at:
    ~/.gnuradio/config.conf (or %APPDATA%\.gnuradio\config.conf on Windows).
  2. Add or append the following section to pass default CMake arguments:
    [grc]
    cmake_opt = -DPYTHON_EXECUTABLE=C:/msys64/ucrt64/bin/python.exe
  3. Restart GNU Radio Companion and trigger the C++ code generation again.

Summary

The D:/M/msys64 error is a known upstream packaging artifact in MSYS2 UCRT64. Correcting the hardcoded path in GrPython.cmake or providing standard variables like Python3_EXECUTABLE directly resolves the issue, allowing you to build, compile, and execute C++ flowcharts smoothly inside GRC.