【问题标题】:How to set the directory of IPython shell in Emacs the same as the python file?如何在 Emacs 中将 IPython shell 的目录设置为与 python 文件相同的目录?
【发布时间】:2013-09-15 02:19:09
【问题描述】:

我正在尝试在 Emacs 中运行 IPython,在 Ubuntu 13.04 上使用 emacs 24.3.1、Python 2.7.4、IPython 0.13.2

当我在 Emacs 中启动 IPython shell 时,它默认为 $HOME 目录。我尝试通过'cd', 'import os, os.chdir()' 切换到我当前的工作目录,但是运行sn-p 代码后,工作目录总是回到$HOME。

有没有办法改变工作目录,或者启动与编辑过的python文件目录相同的Ipython shell?谢谢。

我发现了一个类似的问题Setting the working directory of IPython Shell to that of the python file being executed in Canopy,但不确定如何在 Emacs 中实现...

【问题讨论】:

    标签: python emacs ipython


    【解决方案1】:

    使用 python-mode.el,它应该在 Ubuntu 上可用:

    通过 M-x IPython 运行 IPython

    适用于这种情况的自定义:

    py-execute-directory
    

    设置后,存储文件的默认目录名 py-execute-... 函数作用于。

    分别。

    py-use-current-dir-when-execute-p
    

    t', current directory is used by Python-shell for output ofpy-execute-buffer'及相关命令时。

    【讨论】:

    • 谢谢,我将 (setq py-use-current-dir-when-execute-p t) 添加到我的 .emacs 文件中,然后启动 ipython,当使用 'cd' 时,它会打印我的当前目录;当我们使用 'os.getcwd()' 时,它仍然会打印 HOME 目录......所以该方法只能部分工作。由于我对 Emacs 还很陌生,我想我需要对 python 环境进行更多调整,无论如何,谢谢!
    • @calbear cd /SOME/OTHER/DIR 为我工作。开始时,如果没有自定义 py-execute-directory,则默认为 $HOME。
    猜你喜欢
    • 2013-06-03
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    • 2014-03-21
    • 2012-12-07
    • 1970-01-01
    相关资源
    最近更新 更多