2

I am trying to run IPython in Emacs, using emacs 24.3.1, Python 2.7.4, IPython 0.13.2 on Ubuntu 13.04

When I start an IPython shell within Emacs, it defaults to $HOME directory. I try to change to my current work directory by 'cd', 'import os, os.chdir()', but after running a snippet of code, work directory always goes back to $HOME.

Is there a way to change work directory, or start Ipython shell the same as the directory of the edited python file? Thanks.

I found a similar question Setting the working directory of IPython Shell to that of the python file being executed in Canopy but not sure how to implement in Emacs...

Community
  • 1
  • 1
calbear
  • 77
  • 3

1 Answers1

0

With python-mode.el, which should be available at Ubuntu:

Run IPython via M-x IPython

Customizations applicable in this case:

py-execute-directory

When set, stores the file's default directory-name py-execute-... functions act upon.

resp.

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

When t', current directory is used by Python-shell for output ofpy-execute-buffer' and related commands.

Andreas Röhler
  • 4,804
  • 14
  • 18
  • thanks, I added (setq py-use-current-dir-when-execute-p t) to my .emacs file, then start ipython, when use 'cd', it prints my current directory; when us 'os.getcwd()', it still prints HOME directory... so the method only works partially. Since I'm fairly new to Emacs, I guess I need more tweaking of the python environment, thanks anyway! – calbear Sep 15 '13 at 19:46
  • @calbear cd /SOME/OTHER/DIR works for me. At start, if py-execute-directory isn't customized otherwise, $HOME is the default. – Andreas Röhler Sep 16 '13 at 05:47