pyenv install 3.6.15 fails with ModuleNotFoundError: No module named 'math' on Ubuntu 25.04
Description
Attempting to install Python 3.6.15 using pyenv install 3.6.15 on Ubuntu 25.04 consistently fails with a ModuleNotFoundError: No module named 'math'. This occurs even after installing all recommended build dependencies and setting CFLAGS and LDFLAGS for tirpc.
Steps to Reproduce
-
Initial Attempt:
pyenv install 3.6.15 -
Attempt with Dependencies and Build Flags:
sudo apt update && sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev \ libxmlsec1-dev libffi-dev liblzma-dev libgdbm-dev libgdbm-compat-dev libnsl-dev libtirpc-dev && \ export CFLAGS="-I/usr/include/tirpc" && \ export LDFLAGS="-ltirpc" && \ pyenv install 3.6.15
Expected Behavior
Python 3.6.15 should install successfully without errors.
Actual Behavior
The installation fails with "BUILD FAILED" and the following error in the logs:
ModuleNotFoundError: No module named 'math' make: *** [Makefile:1102: install] Error 1
System Information
- Operating System: Ubuntu 25.04
-
pyenvversion: python-build 20180424 (as indicated in the build output)
Logs
Initial Attempt Log (/tmp/python-build.20250630182547.62437.log) - Last 10 lines:
File "/tmp/python-build.20250630182547.62437/Python-3.6.15/Lib/runpy.py", line 109, in \_get\_module\_details
**import**(pkg\_name)
File "/tmp/python-build.20250630182547.62437/Python-3.6.15/Lib/ensurepip/**init**.py", line 5, in \<module\>
import tempfile
File "/tmp/python-build.20250630182547.62437/Python-3.6.15/Lib/tempfile.py", line 45, in \<module\>
from random import Random as \_Random
File "/tmp/python-build.20250630182547.62437/Python-3.6.15/Lib/random.py", line 42, in \<module\>
from math import log as \_log, exp as \_exp, pi as \_pi, e as \_e, ceil as \_ceil
ModuleNotFoundError: No module named 'math'
make: \*\*\* [Makefile:1102: install] Error 1
Attempt with Dependencies and Build Flags Log (/tmp/python-build.20250630182721.74793.log) - Last 10 lines:
File "/tmp/python-build.20250630182721.74793/Python-3.6.15/Lib/runpy.py", line 109, in \_get\_module\_details
**import**(pkg\_name)
File "/tmp/python-build.20250630182721.74793/Python-3.6.15/Lib/ensurepip/**init**.py", line 5, in \<module\>
import tempfile
File "/tmp/python-build.20250630182721.74793/Python-3.6.15/Lib/tempfile.py", line 45, in \<module\>
from random import Random as \_Random
File "/tmp/python-build.20250630182721.74793/Python-3.6.15/Lib/random.py", line 42, in \<module\>
from math import log as \_log, exp as \_exp, pi as \_pi, e as \_e, ceil as \_ceil
ModuleNotFoundError: No module named 'math'
make: \*\*\* [Makefile:1102: install] Error 1
Please add the necessary diagnostic details as per the issue template
Anyway, WFM in a fresh 25.04 VM. So I've just wasted an hour for nothing.
That's why we request trace logs in the issue template -- looking through them is much faster and reliable than trying to reproduce the problem.