【问题标题】:How can I run a python script using the IPython console in Spyder?如何在 Spyder 中使用 IPython 控制台运行 python 脚本?
【发布时间】:2020-02-25 05:10:21
【问题描述】:

此命令在 Linux 上在bash 下运行:

python file.py variables

但是当我将它写入 Spyder 中的 IPython 控制台时,我得到:

SyntaxError: invalid syntax

:如何在 Spyder 中使用 IPython 控制台运行 python 脚本?

【问题讨论】:

    标签: python bash spyder


    【解决方案1】:

    (这里是 Spyder 维护者) 要在 Spyder 中运行 Python 文件,您只需在其编辑器中打开它并转到菜单

    Run > Run file
    

    或按 F5。这基本上是读取文件的内容并使用exec 执行它(正如 Jeremy Hue 的回答中所建议的那样)。

    如果您想将参数传递给您的脚本,请参阅我对 here 的回答。

    【讨论】:

      【解决方案2】:

      您的 IPython 控制台已经在运行 Python,而 bash 中的命令 python file.py 基本上是在说“使用 Python 运行 file.py”。

      如果您想通过 IPython 控制台显式运行 file.py,请查看此解决方案 run program in Python shell

      【讨论】:

      • 您好,谢谢。 exec(open("C:\\test.py").read()) 命令运行良好。但是你知道调用test.py时如何添加参数/选项吗?
      • 我有这个:python rsatool.py -f PEM -o key.pem -n 13826123222358393307 -d 9793706120266356337。如何将所有参数添加到调用中?谢谢
      • 你将不得不改变你的方法。看看这里stackoverflow.com/questions/5788891/…
      猜你喜欢
      • 1970-01-01
      • 2018-04-30
      • 2018-01-05
      • 2020-10-27
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-09
      • 1970-01-01
      相关资源
      最近更新 更多