15 Feb 2026

Python Setup

Complete workflow to install Python using pyenv and run SymPy-based symbolic algebra along with SciPy numerical integration.

macos python sympy scipy numerical physics

To do symbolic calculation safely and high-quality numerical work, the most practical stack is:

Below is the complete pipeline: install β†’ create environment β†’ install libraries β†’ run tests.

Step 1 β€” Install pyenv (Python version manager)

    brew install pyenv

Add to shell:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

Step 2 β€” Install Python version

Example (stable for scientific work):

    pyenv install 3.11.7

Set global:

    pyenv global 3.11.7
    python --version
    mkdir susy-project
    cd susy-project
    pyenv local 3.11.7

Step 4 β€” Upgrade pip

    pip install --upgrade pip

Step 5 β€” Install required libraries

    pip install sympy numpy scipy

Step 6 β€” Test Symbolic Computation (Supersymmetry style)

Create file:

    touch symbolic_test.py

Example: anticommuting symbols, algebra, simplification

from sympy import symbols, expand

# define operators
A, B = symbols('A B', commutative=False)

expr = (A + B)**2

print("Original expression:")
print(expr)

print("\nExpanded expression:")
print(expand(expr))

Run:

python symbolic_test.py

Step 7 β€” Test Numerical Integration

Create file:

touch numeric_test.py

Example: integrate sin(x) from 0 to pi

import numpy as np
from scipy import integrate

f = lambda x: np.sin(x)

result, error = integrate.quad(f, 0, np.pi)

print("Integral:", result)
print("Estimated error:", error)

Run:

python numeric_test.py

Expected β‰ˆ 2.

Mixed Symbolic-Numeric Example

from sympy import symbols, sin, lambdify
import numpy as np
from scipy.integrate import quad

x = symbols('x')
expr = sin(x)

f = lambdify(x, expr, 'numpy')

res, _ = quad(f, 0, np.pi)
print(res)

Running in Visual Notebook Environment (Mathematica-like Experience)

For a more interactive experience, you can use Jupyter Notebook or JupyterLab. They allow you to run code in cells and see outputs immediately, which is great for experimentation and learning.

pip install jupyterlab notebook

Jupyter provides two interfaces for running interactive Python code:

Jupyter Notebook

Run with: jupyter notebook

JupyterLab

Run with: jupyter lab and if error occurs, try python -m jupyter lab which ensures it uses the correct Python environment.

Both use the same Python kernel and execute code identically. The difference is only in the user interface.

Share This Page