Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

External editor for IPython notebook

I am using IPython notebook and I want to edit programs in an external editor. How do I get the %edit file_name.py to open an editor such as Notepad++.

like image 778
John Avatar asked Mar 28 '13 11:03

John


People also ask

How do I open a Jupyter Notebook in Notepad ++?

3.1. To launch Jupyter Notebook App: Click on spotlight, type terminal to open a terminal window. Enter the startup folder by typing cd /some_folder_name . Type jupyter notebook to launch the Jupyter Notebook App The notebook interface will appear in a new browser window or tab.

Can I use Jupyter Notebook as a text editor?

A Jupyter notebook is neither a simple text editor nor a full-featured IDE. Jupyter notebooks provide a quick and streamlined way for problem-solvers to prototype code and quickly share code.


2 Answers

Running %edit? will give you the help for the %edit magic function.

You need to set c.TerminalInteractiveShell.editor, which is in your ipython_config.py. I'm not quite sure where this is located in Windows; on OS X and Linux, it is in ~/.ipython. You'll want to set the variable to be the full path of the editor you want.

Alternatively, you can create an environment variable EDITOR in Windows itself, and set that equal to the full path of the editor you want. iPython should use that.

like image 118
cge Avatar answered Oct 22 '22 22:10

cge


I'm using Windows 7 and 8 (and 10TP) and Python 3.4.2.

I started with ipython locate to tell me where ipython thought config files suggested elsewhere should be. When I saw it was different I read around and came up with the following:

  • On my system, the ipython locate gave me c:\users\osmith\.ipython, not the _ipython you'll see mentioned in the YouTube videos done with Windows XP,
  • Look in the directory ipython locate specifies for a profile directory; if you aren't actively doing anything with ipython profiles, it should be .ipython\profile_default, if you are using profiles, then I leave it to you to s/profile_default/${YOUR_PROFILE_NAME}/g
  • Check the profile_default directory for a ipython_config.py file, if it's not there, tell IPython to initialize itself: ipython profile create
  • Open the config file in a text editor,

If you are the kind of person who hasn't messed around with their console overly much and installs things in standard places, you can skip straight to this step by typing: ipython profile create followed by start notepad .ipython\profile_default\ipython_config.py.

  • Search for the string c.TerminalInteractiveShell.editor,
  • The comment above this indicates you can also use the EDITOR environment variable, but hard coding file paths never hurt anyone so lets do eet:
  • Copy the line and remove the leading hash and spaces from the copy.
  • Replace the text between the apostrophes ('notepad') with the path of our desired editor, e.g.

    c.TerminalInteractiveShell.editor = 'c:/program files (x86)/noddyeditor/noddy.exe'

There is a catch here, though; some modern editors get a bit fancy and automatically and, when invoked like this, detach from the console. Notepad++ and Sublime Text, for example. Sublime accepts a "--wait" option, which works some of the time; this tells the command invocation to hang around until you close the file, for some definition of until and some other definition of close.

However, the following setting will work most of the time for sublime text:

c.TerminalInteractiveShell.editor = '"c:/program files/sublime text 3/subl.exe" --wait'

(assuming c:\program files\ is where your sublime text 3 directory is)

like image 28
kfsone Avatar answered Oct 22 '22 23:10

kfsone