Ask Your Question
0

using sage as a pure python installation

asked 2026-07-27 07:22:06 +0200

dyne2meter gravatar image

I'm trying to keep some legacy hardware useful and have no package distribution provider that will deliver a working Python installation with numpy/matplotlib ± a few other packages I use regularly. The evidence I have is that the packages I can't use are built allowing AVX instructions and when I try to import numpy, the result is "Bad instruction" or the like. My Sage 10.8 from the 3-manifolds project is the last useable scientific Python I have, and sometimes I want to run a script file simply by something like "# python myscript.py". When I invoke the python executable in the directory

../SageMath.app/Contents/Frameworks/Sage.framework/Versions/10.8/local/bin

I seem to have a working REPL that can import modules, and I have experimented with using this path to run python scripts (some requiring matplotlib, for example) in my shell environment.

My question is how much trouble I can expect to run into by going deeper into this. My system is an old MacPro running MacOS 10.13 (High Sierra).

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2026-07-31 05:38:25 +0200

ortollj gravatar image

Out of curiosity, I asked Copilot to provide a response to your question (I wanted to post this as a comment because it might not be the expected answer, but since the text was too long, it got cut off.) :

When you say that you have “a working REPL that can import modules”, you are essentially reporting that the CPython interpreter embedded inside Sage is fully functional on your machine, including its ability to load extension modules compiled in C, C++, or Fortran.

A REPL (Read–Eval–Print Loop) is simply the interactive CPython shell. The important part is not the REPL itself, but the fact that this interpreter can successfully import extension modules such as NumPy, SciPy, or Matplotlib. These modules contain compiled native code and rely on specific CPU instruction sets.

On macOS 10.13 running on older Intel hardware, the system Python typically fails with errors like “Illegal instruction” or “Bad instruction” when importing modern scientific libraries. This happens because recent wheels for NumPy/SciPy are built with AVX or AVX2 vector instructions, which your CPU does not support. As soon as the dynamic loader tries to execute AVX instructions, the process aborts.

Sage does not use the system Python or system-provided NumPy/SciPy. Instead, Sage builds its own Python environment and compiles its numerical libraries from source, using compiler flags that match the capabilities of your CPU. This is why Sage’s internal Python can import these modules without triggering illegal instruction faults.

In other words:

The Sage Python interpreter is working correctly.

Its extension modules are compiled in a way that is compatible with your CPU.

The system Python fails because its extension modules require AVX instructions that your CPU does not implement.

You can use Sage’s Python interpreter to run standalone scientific scripts. Many users with older hardware do exactly this. The main caveat is that Sage’s Python environment is designed primarily for Sage itself, so internal paths and dependencies may change across Sage releases. As long as you stay on your current Sage installation, this approach is technically sound

edit flag offensive delete link more

Comments

Thanks for a thorough (and even comforting) response! I use Macports, and wonder if I build all the dependencies of the MacPorts py-numpy from source on my machine, might I end up with a system python that does not invoke these AVX vector instructions? I'm certainly going to try: the listed dependencies are OpenBLAS and gfortran, but those may have dependencies I need to check as well. Once again, hearty thanks for your efforts.

dyne2meter gravatar imagedyne2meter ( 2026-08-02 16:55:00 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2026-07-27 07:22:06 +0200

Seen: 110 times

Last updated: Jul 31