This project is educational and Open Source. No code is copied from other emulators. Implementation based solely on technical documentation and permitted tests.
Fix: NumPy Import Error in setup.py
Summary
This step fixes a critical compilation error caused by a corrupt NumPy installation that preventedsetup.pywill be executed correctly.
The errorModuleNotFoundError: No module named 'numpy._core._multiarray_umath'it completely blocked the C++/Cython module compilation process.
Two solutions were implemented: (1)Complete reinstallation of NumPy(uninstall → clear cache → reinstall) and (2)setup.py robustness improvementto optionally and safely handle NumPy, allowing compilation to continue even if NumPy is corrupt or unavailable.
Hardware Concept
Note:This step is not related to the Game Boy hardware, but to the project's build infrastructure.
NumPy is a foundational Python library for high-performance numerical computing. In the context of this hybrid Python/C++/Cython project, NumPy is mainly used for:
- Cython MemoryViews:Transfer video/audio buffers between Python and C++ without copies (zero-copy).
- Includes directories:Provide C headers for integration with C++ code.
- Efficient arrays:For future rendering and audio processing optimizations.
However, NumPyit is not strictly necessaryfor the basic compilation of the current C++ core, since the C++/Cython code does not directly use NumPy arrays in this phase. Therefore, it is possible to make NumPy optional in the build process.
Implementation
Two complementary solutions were implemented:
1. Complete Reinstallation of NumPy
The root issue was a corrupt installation of NumPy 2.3.5 on Python 3.13.5. The solution was:
- Uninstall:
pip uninstall numpy -y - Cache Cleanup:
pip cache purge - Clean reinstall:
pip install --no-cache-dir numpy
This resolved the errorModuleNotFoundError: No module named 'numpy._core._multiarray_umath'.
2. Robustness improvement of setup.py
It was modifiedsetup.pyto handle NumPy optionally and safely:
# Try to import numpy safely (optional)
try:
import numpy
numpy_available = True
numpy_include = numpy.get_include()
except (ImportError, AttributeError) as e:
numpy_available = False
numpy_include = None
print(f"[INFO] NumPy not available or corrupt: {e}")
print("[INFO] Continuing without NumPy (not needed for current build)")
# Build include_dirs
include_dirs = [str(cpp_dir.absolute())]
if numpy_available and numpy_include:
include_dirs.append(numpy_include)
Benefits:
- The build can continue even if NumPy is corrupt or not installed.
- Clear informative messages for the user.
- NumPy is added to
include_dirsonly if it is available and functional. - Development is not blocked if there are problems with NumPy.
Modified components
- setup.py:Optional and safe handling of NumPy with try/except.
Design decisions
Why make NumPy optional?
- Current C++/Cython code does not directly use NumPy arrays.
- NumPy is only needed for
numpy.get_include(), which is optional for the base build. - Making NumPy optional improves the robustness of the build system.
- It allows development to continue even if there are problems with external dependencies.
Affected Files
setup.py- Modified to handle NumPy optionally and safely
Tests and Verification
The verification was carried out by:
- NumPy verification:
Result:python -c "import numpy; print(f'NumPy {numpy.__version__} imported successfully')"NumPy 2.3.5 imported successfully✅ - Checking setup.py:
Result:No import errors ✅python -c "exec(open('setup.py').read().split('setup(')[0])" - Compilation:The script
rebuild_cpp.ps1can now run without NumPy errors.
Note:The C++ core unit tests were not run in this step, as the goal was only to correct the compilation issue.
Sources consulted
- NumPy Documentation:Troubleshooting ImportError
- Python Packaging:Python Packaging User Guide
- Cython Documentation:Cython Documentation
Educational Integrity
What I Understand Now
- Optional dependency management:It is important to make non-critical dependencies optional in build scripts to improve system robustness.
- Error handling in setup.py:Using try/except for optional imports allows the build process to continue even if there are problems with external dependencies.
- Clean reinstallation of packages:When a package is corrupt, the most effective solution is to uninstall it completely, clear the pip cache, and reinstall it from scratch.
What remains to be confirmed
- Verify that the entire build works correctly with NumPy reinstalled.
- Confirm that the compiled module works correctly after the fix.
Hypotheses and Assumptions
NumPy 2.3.5 is assumed to be compatible with Python 3.13.5. If there are compatibility problems in the future, it may be necessary to use a specific version of NumPy or wait for updates.
Next Steps
- [ ] Verify that the entire build works:
.\rebuild_cpp.ps1 - [ ] Run C++ core tests to confirm everything is working correctly
- [ ] Continue with the development of Phase 2 (APU, optimizations, etc.)