如何从命令行运行IPython脚本-使用魔法函数时出现语法错误,%

如何从命令行运行IPython脚本-使用魔法函数时出现语法错误,%,ipython,ipython-magic,Ipython,Ipython Magic,我想从命令行运行IPython。但是,我在第一行得到了一个语法错误,使用神奇的函数%pylab导入pylab会在%上产生语法错误。我使用的命令只是ipython-iscript.py 有没有办法解决这个问题?您需要将文件命名为script.ipy。当它以.ipy结尾时,它可以包含ipython语法 从ipython--help: Usage ipython [subcommand] [options] [files] If invoked with no options, i

我想从命令行运行IPython。但是,我在第一行得到了一个语法错误,使用神奇的函数
%pylab
导入pylab会在%上产生语法错误。我使用的命令只是
ipython-iscript.py


有没有办法解决这个问题?

您需要将文件命名为script.ipy。当它以.ipy结尾时,它可以包含ipython语法

ipython--help

Usage

    ipython [subcommand] [options] [files]

    If invoked with no options, it executes all the files listed in sequence
    and exits, use -i to enter interactive mode after running the files.  Files
    ending in .py will be treated as normal Python, but files ending in .ipy
    can contain special IPython syntax (magic commands, shell expansions, etc.)