@[TOC](Use SageMath with PyCharm (Use PyCharm to run and debug SageMath scripts))
编辑:LLL
审稿:百新科技

SageMath

SageMath is a free open-source mathematics software system.

https://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/
https://blog.csdn.net/hardwork617s/article/details/110875291

Install SageMath on Ubuntu 16.04/18.04

sudo apt-add-repository -y ppa:aims/sagemath
sudo apt-get update
sudo apt install sagemath-upstream-binary  sagemath-upstream-binary-full
#sudo apt install python-z3
sudo apt install z3
sudo pip2 install z3-solver  #Install z3-solver for Python2

Debug/Running Sage scripts with PyCharm

1. Set environment variables

(1) Run the command sage -sh to start subshell with Sage environment variables set. Then, you can run sage scripts (**.py) by running the command python **.py.
Also, you can check the environment variables setting of SageMath with the command printenv | fgrep SAGE.
(2) Add the following environment variables set into /etc/profile

export SAGE_ROOT=/usr/lib/sagemath
export SAGE_LOCAL=/usr/lib/sagemath/local
export SINGULAR_EXECUTABLE=/usr/lib/sagemath/local/bin/Singular
#export DOT_SAGE=/home/chengzi/.sage/

For PyCharm, the variables set in /etc/profile are system ones. They can be obtained when running/debugging programs with the run menu of PyCharm, and also can be used in the terminal and console of PyCharm.
(3) Install Singular

sudo apt install singular-ui

2. Set the python interpreter in to use Sage’s python interpreter

  • The Sage’s python interpreter (7.5.1) locates /usr/lib/sagemath/local/bin/python2.7.
  • Then, we add Sage’s Python interpreter to PyCharm’s list of available interpreters. From the Welcome screen click on the little “Configure” gear and select “Settings” from the menu.
    In the settings page select “Project Intepreter”–this is where you can add additional interpreters for use across projects.
  • Click the little gear icon in the top-right corner next to the drop-down list of available interpreters, and select “Add Local” from the menu. Then from the list of interpreter types, select “System Interpreter”.
  • Copy /usr/lib/sagemath/local/bin/python2.7 directly into the file browser.
  • If you set up the correct environment variables, PyCharm should be able to successfully execute Sage’s Python interpreter.
  • PyCharm now recognises the Sage python. You should be able to from sage.all import * and use Sage objects in plain Python.

Basic usage of SageMath

(1)使用sage -t .py命令运行python代码时,需要将.py文件所在目录添加到环境变量SAGE_PATH中,否则无法调用python中的module,会出现no module ***的错误。
Execute the following command in the terminal.

export SAGE_PATH=/home/chengzi/Downloads/dig-dev
echo $SAGE_PATH

(2)To run Sage scripts, you can use the command sage -python **.py.

Update functions in SageMath

DeprecationWarning: CartesianProduct is deprecated. Use cartesian_product instead

sage: cp = CartesianProduct([1,2], [3,4]);cp
doctest:...: DeprecationWarning: CartesianProduct is deprecated. Use
cartesian_product instead
See http://trac.sagemath.org/18411 for details.
The Cartesian product of ({1, 2}, {3, 4})
sage: cp.list()
[(1, 3), (1, 4), (2, 3), (2, 4)]F=[[1,2], [3,4]]
sage: cp = cartesian_product(list(F));cp
sage: F1 = ['a', 'b']
sage: F2 = [1, 2, 3, 4]
sage: c = cartesian_product([F1, F2])
sage: c
The Cartesian product of ({'a', 'b'}, {1, 2, 3, 4})
sage: c.list()[('a', 1),('a', 2),('a', 3),('a', 4),('b', 1),('b', 2),('b', 3),('b', 4)]

Use SageMath with PyCharm/PyDev (Use PyCharm/PyDev to run and debug SageMath scripts)相关推荐

  1. 在Ubuntu 18中安装Pycharm及创建Pycharm快捷方式

    微信公众号: 吴甜甜的博客 我的个人网站: wutiantian.github.io 在Ubuntu 18中安装Pycharm及创建Pycharm快捷方式 一.在Ubuntu18.04中安装Pycha ...

  2. pycharm安装教程-pycharm安装详细步骤(Mac版)

    上期跟大家讲了怎么安装Python,这期跟大家介绍个很好用的编程工具–pycharm. PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比 ...

  3. PyCharm必看--PyCharm基础使用手册

    PyCharm必看–PyCharm基础使用手册 文章目录 PyCharm必看--PyCharm基础使用手册 PyCharm 之编码设置 PyCharm 之字体设置 PyCharm 之主题设置 设置主题 ...

  4. 在Anaconda3(D盘)中安装PyInstaller第三方库并导入pycharm,在PyCharm中和使用PyInstaller对py程序进行打包的方法

    安装PyInstaller第三方库: 本人采用的是Pycharm+Anaconda3,PyCharm装在D盘PyCharm文件夹,Anaconda3装在D盘Anaconda3文件夹. 安装时打开Ana ...

  5. PyCharm专业版和PyCharm社区版有什么区别?

    好多初用pycharm的朋友,不知道PyCharm专业版和PyCharm社区版的区别,总体而说pycharm pro 2019 mac是一种Python IDE,带有一整套可以帮助用户在使用Pytho ...

  6. python专业版如何激活_学生如何注册Pycharm专业版以及pycharm的安装

    一.python开发环境安装与配置 1.python的下载 2.安装 (1)双击安装程序进入如下所示的界面进行勾选并确定安装方式. (2)点击Customize installation,之后出现op ...

  7. [Python]_[初级]_[使用PyCharm时不识别根包位置和Debug时报ModuleNotFoundError错误]

    场景 在使用PyCharm开发程序时,当我们Debug某个文件时,会报以下错误,什么原因? Traceback (most recent call last):File "C:\Progra ...

  8. python环境变量配置_python+ pycharm 环境安装 + pycharm使用

    一.下载和安装python 1.可以搜索python官网找到官方链接点击进入 2.也可以用以下链接点击进入:https://www.python.org/ 3.进入python后把鼠标移到downlo ...

  9. pycharm 导入或复制项目后run按钮灰色问题(显示pycharm add configuration)

    我直接按快捷键ctrl+shift+F10解决了 参考文章:解决pycharm新建项目后按钮灰色问题

  10. pycharm python3_为什么pycharm找不到python3

    Pycharm默认的Python是python2,但是如果代码是python3写的,就需要在pycharm里的project interpreter增加python3 注意,一定要找到Project ...

最新文章

  1. javascript晚绑定_JavaScript的应用,调用和绑定通过托管野餐来解释
  2. Spring和SpringMVC自动扫描注解类的冲突问题
  3. python 生成时间序列
  4. c语言五子棋判断如何胜利,c语言 五子棋危险判断 求大神解释啊
  5. 推荐算法矩阵分解实战——keras算法练习
  6. Silverlight C# 游戏开发:Flyer09扇动翅膀的蝴蝶
  7. 安卓入门系列-01开发工具Android Studio的安装
  8. $_FILE函数总结
  9. .NET CORE 怎么样从控制台中读取输入流
  10. Polo the Penguin and Matrix
  11. hadoopsdk使用_hadoop部署使用问题及解决
  12. 灰度董事总经理:BTC突破2万美元并不令人惊讶
  13. iphone已停用怎么解锁_iPhone X已停用 连接iTunes 怎么办
  14. libpcap 中的 struct block
  15. Wincc RT Professional第一讲-组态
  16. 大学计算机基础vfp程序设计课程试验报告簿,VF程序设计实验报告册(实践教程).doc...
  17. 模拟行走机器人-c语言
  18. wifidog认证php,ddwrt+wifidog搭建热点认证系统(无线路由器web认证)
  19. 手机浏览器自动打开快应用?
  20. 达梦数据库关闭 消息校验的警告 Failure occurs in data_recv_inet_once

热门文章

  1. html 图片下载浏览器默认会打开新页面预览图片解决方案
  2. 程序员内部培训与个人发展杂谈
  3. 多媒体系统导论 实验一:基于Photoshop的图像处理
  4. matlab解三次方程,并且输出图像
  5. Python 使用turtle在画布的随机位置绘制颜色随机的五角星
  6. Android多媒体功能开发(10)——使用MediaRecorder类录制音频
  7. 计算机窗口的排列和切换,win10系统操作多窗口显示排列切换的方案介绍
  8. Protel Dxp2004 创建库
  9. 计算机毕业设计Java校友闲置书籍管理平台(源码+系统+mysql数据库+Lw文档)
  10. Windows10 桌面显示“我的电脑”