用Mathematica运行python代码的方法

 时间:2026-04-22 21:26:11

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

用Mathematica运行python代码的方法

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

用Mathematica运行python代码的方法

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

用Mathematica运行python代码的方法

4、在Mathematica里面运行下面的代码,再检测一次python的zmq模块是否安装成功:

FindExternalEvaluators["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)"的时候,会报错:

ExternalEvaluate["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 range(10) ]"] // Column

用Mathematica运行python代码的方法

  • 如何在matlab中自定义极坐标区?
  • 怎么用MATLAB画二维图
  • 干货Mathematica,加图例,坐标轴文字,实虚线
  • MATLAB学习与使用:简易等值线图(ezcontour)
  • Mathematica基础——关于坐标轴
  • 热门搜索
    苹果快捷键怎么设置 冠珠瓷砖怎么样 我们怎么了 网络怎么赚钱 签证怎么办理 卖股票手续费怎么算 怎么推广 华泰证券怎么样 乘法口诀表怎么背得快 vase怎么读