SageMath Installation
SageMath is a free open-source mathematics software system that builds on many existing open-source packages, including NumPy, SciPy, matplotlib, Sympy, Maxima, GAP, FLINT, R, and more. Unlike proprietary software like Magma, Maple, Mathematica, and MATLAB, Sage is free to use and allows you to view and modify the source code. If you're familiar with Python, you'll feel right at home with Sage as it extends Python with a robust set of mathematical tools.
The easiest way to get started with Sage is by running code in a browser-based workbook on a platform called CoCalc. CoCalc's free tier offers several benefits, including collaboration, automatic dependency management, and the convenience of executing Sage code without installing the software locally. However, after using CoCalc for a while, I found myself wanting a faster setup, free from the limitations of a cloud environment. This led me to install Sage locally on my machine.
If you're running Windows, installing Sage requires a few extra steps.
- Download Windows Subsystem for Linux. Make sure you are using WSL2.
- Reading Set up a WSL development environment is also helpful.
You can find instructions for local installation in the Sage Installation Guide.
There are several ways to install Sage, each with its advantages. Installing Sage from source offers the most flexibility, but it's a lengthy process that may present some challenges. Installing the necessary dependencies can take a considerable amount of time, and the make command — used to build Sage — will also require some patience, depending on your computer's resources.
For those seeking a simpler and quicker installation process, using conda-forge is an excellent alternative. Conda-forge is a community-driven collection of packages for conda, making it easy to install and manage Sage without dealing with the complexities of a source build. Here's how to get started:
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" bash Miniforge3-$(uname)-$(uname -m).sh conda create -n sage sage python=3.11
After installing Sage via conda, you'll see a message similar to the following. Pay attention to the instructions provided, as they guide you on how to activate and manage your new Sage environment:
Transaction finished To activate this environment, use: micromamba activate /home/samuel-lubliner/miniforge3 Or to execute a single command in this environment, use: micromamba run -p /home/samuel-lubliner/miniforge3 mycommand installation finished. Do you wish to update your shell profile to automatically initialize conda? This will activate conda on startup and change the command prompt when activated. If you'd prefer that conda's base environment not be activated on startup, run the following command when conda is activated: conda config --set auto_activate_base false You can undo this by running `conda init --reverse $SHELL`? [yes|no] [no] >>> no
This prompt asks whether you want conda to automatically initialize every time your shell starts. I prefer to keep my environment clean, so I chose no. This choice keeps the base environment inactive on startup, which helps prevent cluttering the command prompt with unnecessary environment activations. If you prefer this setup, type no when prompted.
You have chosen to not have conda modify your shell scripts at all. To activate conda's base environment in your current shell session: eval "$(/home/samuel-lubliner/miniforge3/bin/conda shell.YOUR_SHELL_NAME hook)" To install conda's shell functions for easier access, first activate, then: conda init Thank you for installing Miniforge3!
Manually activating your environment ensures that you maintain control over when and how your conda environments are loaded. This approach is beneficial if you use multiple environments.
Since I opted not to have conda modify my shell scripts, I run Sage manually using the following commands. This method ensures a clean environment and gives me control over when to activate Sage:
samuel_lubliner@DESKTOP-QGSGOAI:~$ eval "$(/home/samuel_lubliner/miniforge3/bin/conda shell.bash hook)" (base) samuel_lubliner@DESKTOP-QGSGOAI:~$ conda activate sage (sage) samuel_lubliner@DESKTOP-QGSGOAI:~$ sage -n jupyter
- The first command initializes conda in your current shell.
- The second command activates the sage environment.
- The third command starts Sage with the Jupyter notebook interface.
Notice that (base) indicates the conda base environment is activated, and (sage) shows that the sage environment is active. Running these commands each time can become repetitive, so let's automate this process by creating a bash script. We can create the file sage_nb.sh. If you are using WSL, the docs recommend:
#!/bin/bash # Switch to desired windows directory cd /mnt/c/path/to/desired/starting/directory # Start the Jupyter notebook SAGE_ROOT/sage --notebook # Alternatively you can run JupyterLab - delete the line above, and uncomment the line below #SAGE_ROOT/sage --notebook jupyterlab
In my case, I installed JupyterLab because I prefer its more modern interface. Here is my script:
#!/bin/bash # Start JupyterLab /home/samuel_lubliner/miniforge3/envs/sage/bin/sage --notebook jupyterlab
To run the script, you first need to make it executable:
chmod ug+x ~/sage_nb.sh
Now you can run the script whenever you want to start Sage:
cd ~ ./sage_nb.sh
If everything is set up correctly, running the script will start the Jupyter server in your terminal. From here, you can begin working with Sage in your browser.
If you prefer a more user-friendly approach, you can take this bash script a step further by creating a clickable shortcut on your desktop. This allows you to start Sage and JupyterLab with a double-click. You can find detailed instructions on how to create this shortcut in the SageMath docs.
The above is the detailed content of SageMath Installation. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.
