Linux,python3:命令行上的语法错误,但在ipython %run command中没有



这个简单的代码在第 6 行项 "'('" 上生成语法错误 从命令行以 # ./main.py 运行时


import matplotlib.pyplot as plt
import numpy as np
# create a top-level Figure object
# with some optional customizations
fig = plt.figure('Population density',figsize=(5./2.254,5./2.254),facecolor='red',edgecolor='green')
# creating an Axes object containing axex and the rest
# we plot on the ax object of class Axes
ax = fig.add_subplot(111)
# we plot data with ax.plot
x = np.linspace(-2,2,1000)
line_cosh, = ax.plot(x, np.cosh(x))
line_quad, = ax.plot(x, 1+x**2/2)
plt.show()

除非使用 %run 在 IPYTHON 中运行时,否则将显示该图。


iPython 通过 %run

问题:语法错误在哪里?

add

!/usr/bin/env python

在 Linux 中从命令行运行的 Python 脚本顶部

最新更新