如何从命令行运行IPython脚本 - 魔术函数的语法错误,%

Che*_*het 7 ipython ipython-magic

我想从命令行运行IPython.但是,我在第一行遇到语法错误,使用magic函数导入pylab会%pylab在%上给出语法错误.我正在使用的命令很简单ipython -i script.py.

任何想法如何解决这个问题?

dit*_*kin 6

您需要将文件命名为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.)
Run Code Online (Sandbox Code Playgroud)