linux - linux,python3:命令行上的语法错误,但在 ipython %run 命令中没有
问题描述
这个简单的代码在命令行中以 # ./main.py 运行时会在第 6 行项目“`('”上生成语法错误
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
问题:语法错误在哪里?
解决方案
添加
!/usr/bin/env 蟒蛇
在 linux 中从命令行运行的 python 脚本的顶部
推荐阅读
- javascript - 如何使用 React Native 应用程序在 Firebase 中添加数据?
- php - PHP 检查当前时间的分钟数是否大于变量值
- .net - 在测试中排除某些目标的最佳做法是什么?
- php - 使用 simplHtmlDom 找不到任何东西
- python - 在python中将整数转换为hh:mm:ss
- r - R xgboost 错误,输入数据包含“inf”或“nan”,但它之前已经工作过
- reactjs - 使用 mapStateToProps (react-redux) 与 store.getState() 时 this.props 中收到的值的差异
- python - Python复制列表并添加新元素
- python - 如何将 Python3 升级后的代码恢复到原始版本?
- vlang - 在 vlang 中将字符串转换为数组