登录
首页 >  文章 >  python教程

SageMath 安装

来源:dev.to

时间:2024-08-16 12:51:48 405浏览 收藏

目前golang学习网上已经有很多关于文章的文章了,自己在初次阅读这些文章中,也见识到了很多学习思路;那么本文《SageMath 安装》,也希望能帮助到大家,如果阅读完后真的对你学习文章有帮助,欢迎动动手指,评论留言并分享~

SageMath 安装

sagemath 是一个免费的开源数学软件系统,它构建在许多现有的开源软件包之上,包括 numpy、scipy、matplotlib、sympy、maxima、gap、flint、r 等。与 magma、maple、mathematica 和 matlab 等专有软件不同,sage 可以免费使用,并允许您查看和修改源代码。如果您熟悉 python,您会对 sage 感到宾至如归,因为它通过一组强大的数学工具扩展了 python。

开始使用 sage 的最简单方法是在名为 cocalc 的平台上基于浏览器的工作簿中运行代码。 cocalc 的免费层提供了多种好处,包括协作、自动依赖关系管理以及无需在本地安装软件即可方便地执行 sage 代码。然而,在使用 cocalc 一段时间后,我发现自己想要更快的设置,不受云环境的限制。这导致我在我的机器上本地安装 sage。

如果您运行的是 windows,安装 sage 需要一些额外的步骤。

  1. 下载适用于 linux 的 windows 子系统。确保您使用的是 wsl2。
  2. 阅读设置 wsl 开发环境也很有帮助。

您可以在 sage 安装指南中找到本地安装的说明。

安装 sage 有多种方法,每种方法都有其优点。从源代码安装 sage 提供了最大的灵活性,但这是一个漫长的过程,可能会带来一些挑战。安装必要的依赖项可能需要相当长的时间,并且用于构建 sage 的 make 命令也需要一些耐心,具体取决于您的计算机资源。

对于那些寻求更简单、更快的安装过程的人来说,使用 conda-forge 是一个很好的选择。 conda-forge 是社区驱动的 conda 软件包集合,可以轻松安装和管理 sage,而无需处理源代码构建的复杂性。以下是如何开始:

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

通过 conda 安装 sage 后,您将看到类似以下内容的消息。请注意提供的说明,因为它们指导您如何激活和管理新的 sage 环境:

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

此提示询问您是否希望 conda 在每次 shell 启动时自动初始化。我更喜欢保持环境清洁,所以我选择了否。此选择使基础环境在启动时保持非活动状态,这有助于防止命令提示符因不必要的环境激活而混乱。如果您喜欢此设置,请在出现提示时输入 no。

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!

手动激活您的环境可确保您保持对 conda 环境加载时间和方式的控制。如果您使用多个环境,此方法很有用。

由于我选择不让 conda 修改我的 shell 脚本,因此我使用以下命令手动运行 sage。这种方法确保了一个干净的环境,并让我可以控制何时激活 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
  • 第一个命令在当前 shell 中初始化 conda。
  • 第二条命令激活 sage 环境。
  • 第三条命令使用 jupyter notebook 界面启动 sage。

注意,(base) 表示 conda base 环境已激活,(sage) 表示 sage 环境已激活。每次运行这些命令可能会变得重复,因此让我们通过创建 bash 脚本来自动化此过程。我们可以创建文件 sage_nb.sh。如果您使用 wsl,文档建议:

#!/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

就我而言,我安装了 jupyterlab,因为我更喜欢它更现代的界面。这是我的脚本:

#!/bin/bash
# start jupyterlab
/home/samuel_lubliner/miniforge3/envs/sage/bin/sage --notebook jupyterlab

要运行脚本,您首先需要使其可执行:

chmod ug+x ~/sage_nb.sh

现在您可以在任何想要启动 sage 的时候运行该脚本:

cd ~
./sage_nb.sh

如果一切设置正确,运行脚本将在终端中启动 jupyter 服务器。从这里开始,您可以开始在浏览器中使用 sage。

如果您喜欢更用户友好的方法,您可以通过在桌面上创建可单击的快捷方式来进一步使用此 bash 脚本。这允许您双击启动 sage 和 jupyterlab。您可以在 sagemath 文档中找到有关如何创建此快捷方式的详细说明。

今天关于《SageMath 安装》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!

声明:本文转载于:dev.to 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>