linux,python3:命令行中出现语法错误,但ipython%run命令中未出现

时间:2018-06-23 13:52:05

标签: linux python-3.x matplotlib

此简单代码在第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

问题:语法错误在哪里?

1 个答案:

答案 0 :(得分:0)

添加

!/ usr / bin / env python

在Linux命令行中运行的python脚本之上