用Mathematica运行python代码的方法

 时间:2024-10-12 09:30:09

1、首先,确保你的电脑上安装了python和Mathematica11.2。

用Mathematica运行python代码的方法

2、用pip为python安装扩展包zmq。

用Mathematica运行python代码的方法

3、安装成功之后,出现下图情形。

用Mathematica运行python代码的方法

4、在Mathematica里面运行下面的代码,再检测一次python的zmq模块是否安装成功:FindExternal呶蓟鹭毵Evaluators["Python"]出现下图的类似情形,表示安装成功了。

用Mathematica运行python代码的方法

5、在Mathematica上,调用python计算sum(range(10)):ExternalEvaluate["Python", "sum(range(10))"]

用Mathematica运行python代码的方法

6、调用python运行"for i in range(10):print(i**2)"的时候,会报错:Externa造婷用痃lEvaluate["Python", "for i in range(10):print(i**2)"]被告知,需要把结果转化为字符串,否则不能被Wolfram语言所识别。可是,结果却出来了,这是咋回事呢?

用Mathematica运行python代码的方法

7、新建一个python文件,内容是:for i in range(10): print(i**2)运行之后,内容如下。

用Mathematica运行python代码的方法

8、在Mathematica里面,一个可行的方法是:ExternalEvaluate[争犸禀淫"Python", "[ i**2 for i in rang髫潋啜缅e(10) ]"] // Column

用Mathematica运行python代码的方法
  • 如何在matlab中自定义极坐标区?
  • 怎么用MATLAB画二维图
  • 干货Mathematica,加图例,坐标轴文字,实虚线
  • MATLAB学习与使用:简易等值线图(ezcontour)
  • Mathematica基础——关于坐标轴
  • 热门搜索
    如何开户 如何合并单元格 微信中如何删除好友 哪里旅游最好玩 欧路莎卫浴怎么样 德宏旅游 永安旅游 京东e卡如何使用 公司倒闭员工怎么赔偿 移动空调效果怎么样