C++ Headers Not Found with pip install on MSYS2/Mingw64 for OpenBLAS

Abstract: Resolve C++ headers not found errors when installing OpenBLAS via pip on MSYS2/Mingw64 by using the correct MinGW64 shell and installing the mingw-w64-x86_64-toolchain package.

Created: 2026-09-24 by
The error occurs because pip attempts to build OpenBLAS from source using a C compiler that cannot locate the necessary C++ standard library headers provided by MSYS2. This is not a Python issue but a toolchain configuration problem where the environment variables for include paths are missing or misconfigured during the compilation phase.

Understanding the MSYS2 Environment

MSYS2 provides multiple terminal environments, each with different default configurations. The most common mistake is running pip install inside the generic msys2_shell.cmd or the base MSYS2 shell. These shells use the msys-2.0.dll runtime and are designed for POSIX-like tools, not for compiling Windows native applications. To compile C++ code on Windows using MinGW-w64, you must use the specific terminal shortcut named UCRT64 or MINGW64. The MINGW64 shell sets up the correct PATH to point to /mingw64/bin, which contains the GCC and G++ compilers linked against the UCRT (Universal C Runtime) or MSVCRT. When you run which gcc in this shell, it should return /mingw64/bin/gcc.exe. If it returns /usr/bin/gcc, you are in the wrong shell, and header resolution will fail. For more details on building C code in similar cross-platform environments, see Building and Running C++ Code in WSL2 (Linux Debian) with Mingw - Not Always the Last One Running. While WSL2 is Linux-based, the principle of ensuring the correct compiler toolchain is active before invoking build systems remains identical.

Installing Required Development Packages

Before installing any Python package that requires compilation, you must ensure the underlying C++ development headers are present in your MSYS2 installation. Open your preferred MinGW64 terminal and execute the following command:
pacman -S mingw-w64-x86_64-toolchain
pacman -S mingw-w64-x86_64-gcc
This installs the GNU Compiler Collection and associated headers into the /mingw64/include directory. Specifically, look for files like cxxabi.h or bits/c++config.h in that path. If these files are missing, the C++ standard library is incomplete, and any package attempting to link C++ code will fail immediately. You may also need to install the specific BLAS/LAPACK development libraries if they are required as dependencies, though OpenBLAS usually bundles its own sources. However, having the base toolchain is non-negotiable.

Configuring the Build Environment

When pip builds OpenBLAS, it invokes a setup script that calls the system compiler. By default, this compiler might not know where to find the MSYS2-specific headers if the environment is not properly exported. You can verify your current include paths by running:
gcc -print-search-dirs | grep "programs: ="
If the output does not show /mingw64/lib/gcc/... or /mingw64/include/..., your PATH is incorrect. Ensure that /mingw64/bin appears before /usr/bin in your PATH variable. In the MinGW64 shell, this is handled automatically. If you are using an external IDE or a custom script, you may need to manually export the CXX and CC variables:
export CC=/mingw64/bin/gcc
export CXX=/mingw64/bin/g++
This forces the build system to use the correct compiler wrappers that understand the MSYS2/MinGW ABI. Without this, pip might fall back to a different compiler or fail to detect the C++ support entirely.

Resolving the Externally Managed Environment Error

Recent versions of Python (3.11+) enforce PEP 668, which prevents pip from modifying system-wide packages unless explicitly allowed. If you encounter the error ERROR:externally-managed-environment, you cannot simply ignore it by using --break-system-packages without understanding the risks. Instead, use a virtual environment. Create a virtual environment in your project directory:
python -m venv .venv
source .venv/bin/activate
Once activated, all subsequent pip install commands operate within this isolated scope, bypassing the externally managed check. This is the recommended practice for all Python projects. For more information on managing dependencies safely, refer to Error: Externally managed Environment,PIP. If you prefer not to use virtual environments, you can force the installation, but this is discouraged for production systems. Alternatively, consider using pipx for global CLI tools, though it is less suitable for library dependencies like OpenBLAS. See How to use pipx install -r? for context on alternative installation methods.

Final Verification

After successfully installing the package, verify that the C++ bindings are accessible. Create a simple test file test.cpp:
#include <iostream>
int main() {
    std::cout << "OpenBLAS installed correctly" << std::endl;
    return 0;
}
Compile it using the MinGW64 compiler:
g++ test.cpp -o test.exe
./test.exe
If this runs without errors, your toolchain is correctly configured, and the previous header issues were likely due to shell confusion or missing packages.

Frequently Asked Questions

Why does pip work in MSYS2 shell but fail in MinGW64 shell?

This is rare but possible if the MSYS2 shell has pre-installed binary wheels cached. Generally, pip fails in MSYS2 because the POSIX-style paths interfere with Windows-native compilers. Always prefer the MinGW64 shell for native Windows Python packages.

Can I use MSVC instead of MinGW for OpenBLAS?

Yes, but you must have Visual Studio Build Tools installed. Pip will detect the MSVC compiler if it is in the PATH. However, mixing MSVC and MinGW headers causes severe conflicts. Stick to one toolchain per environment.

What if I get 'libgfortran' not found errors?

OpenBLAS depends on Fortran libraries. Ensure you have installed mingw-w64-x86_64-gcc-fortran via pacman. The shared libraries must be in your system PATH or copied to the Python scripts directory.

Is it safe to use --break-system-packages?

No. It breaks Python's dependency isolation guarantees and can cause conflicts between system updates and pip-installed packages. Use virtual environments or conda instead.

How do I clear the pip cache if a build failed halfway?

Run pip cache purge to remove cached wheels and source distributions. This forces pip to re-download and rebuild the package, which can resolve intermittent build failures caused by corrupted downloads.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More