ModuleNotFoundError: No module named 'math'
Asked Answered
T

3

14

When I try to install a python version using pyenv, I get the following error:

$ pyenv install 3.5.7
Downloading Python-3.5.7.tar.xz...
-> https://www.python.org/ftp/python/3.5.7/Python-3.5.7.tar.xz
Installing Python-3.5.7...

BUILD FAILED (CentOS release 6.10 (Final) using python-build 1.2.13)

Inspect or clean up the working tree at /tmp/python-build.20190726132219.7116
Results logged to /tmp/python-build.20190726132219.7116.log

Last 10 log lines:
  File "/tmp/python-build.20190726132219.7116/Python-3.5.7/Lib/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/tmp/python-build.20190726132219.7116/Python-3.5.7/Lib/ensurepip/__init__.py", line 5, in <module>
    import tempfile
  File "/tmp/python-build.20190726132219.7116/Python-3.5.7/Lib/tempfile.py", line 45, in <module>
    from random import Random as _Random
  File "/tmp/python-build.20190726132219.7116/Python-3.5.7/Lib/random.py", line 41, in <module>
    from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ImportError: No module named 'math'
make: *** [Makefile:1048: install] Error 1
Truthvalue answered 26/7, 2019 at 13:26 Comment(3)
Just came across this error on Ubuntu 18.04 using python-build 20180424... did you find a solution?Personable
I also have this problem. This is strange. python -c 'import math' works as expected.Thomasinethomason
This seems to happen more-often-than-usual on platforms such as Cygwin. So, I'm expecting it to be some sort of library incompatibility / inconsistency, somewhere?Intuitive
A
1

My issue on mac was because I uncommented export ARCHFLAGS="-arch x86_64" in the .zshrc file

Almanza answered 6/12, 2022 at 13:12 Comment(1)
This was my issue. New mac, old .zshrc. Discussion here of the proper value of ARCHFLAGS on apple siliconCerys
P
0

My python system version was pointing to an anaconda binary instead of the /usr/bin/python, uninstalling anaconda worked for me.

Note I also had to remove it from my $PATH, and restart my shell, otherwise the installer looks for gcc in the now deleted anaconda directory

Pantin answered 20/3, 2022 at 13:56 Comment(0)
R
0

Make sure the pip knows where it is looking for the installed files; if the files have been deleted, corrupted, or saved in another area, Python won't hesitate to throw up an error message.

Roadbed answered 17/7, 2023 at 10:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.