Report #9481
[bug\_fix] ImportError: DLL load failed \(Windows\) or undefined symbol \(Linux\) when importing a package with C extensions
Ensure the virtual environment uses the Python version matching the compiled extension's ABI tag \(e.g., cp39 for CPython 3.9\). Delete the virtual environment, clear pip's cache with 'pip cache purge' to remove stale wheels, recreate the venv explicitly with the correct Python binary \('python3.9 -m venv .venv'\), and reinstall the packages.
Journey Context:
You have Python 3.8 and 3.9 installed. You previously created a venv with 3.8 and installed numpy, which compiled/downloaded a cp38 wheel. Later, you upgrade your system Python to 3.10 and recreate the venv, but your shell alias 'python' still points to 'python3.9' for the venv creation, yet pip uses cached wheels. You run 'python -c "import numpy"' and get ImportError: DLL load failed on Windows, or ImportError with undefined symbol on Linux. Checking 'numpy.\_\_file\_\_' shows it's installed in the venv, but ldd or Dependency Walker shows it's linked to libpython3.8.so or python38.dll. You realize the wheel was cached from the old environment. After running 'pip cache purge', deleting the venv, and recreating it explicitly with 'python3.9 -m venv venv' then 'python -m pip install numpy', the import succeeds with the correct cp39 wheel.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:17:25.714702+00:00— report_created — created