115

I am trying to copy cells from one jupyter notebook to another. How this is possible?

Ahmad Sultan
  • 1,621
  • 2
  • 13
  • 19

7 Answers7

106

This feature has been introduced in Jupyter Notebook 5.0. Use pip install notebook --upgrade to upgrade to the latest release.

The old shortcuts C, V and X work only for copying and pasting inside one notebook. In order to do it across tabs, you should use Ctrl-C and Ctrl-V (Cmd-C and Cmd-V on Mac).

Note on multiple cells: currently (jupyter 6.0.0) on Mac+chrome using shift-click to select the cells then cmd-C does NOT work, while using the keyboard with shift-down-arrow does! (thanks drevicko for pointing this out)

Abramodj
  • 5,709
  • 9
  • 49
  • 75
Nikolai K.
  • 1,221
  • 1
  • 10
  • 14
  • 2
    `pip install notebook --upgrade` worked for me only up to version 4.3, but `pip install notebook==5.1.0rc2` did it's thing – Pafnucy Aug 24 '17 at 08:40
  • 3
    Your method only works for me to copy and paste markup cells across jupyter notebooks. When I do `Ctrl - C` on code cells, it just sends me to Edit Mode. What did I do wrong here? Thanks. – Bowen Liu Jan 18 '19 at 15:13
  • 2
    This does not work in Firefox (see: [bug](https://github.com/jupyter/notebook/issues/1163)) – sophros Apr 09 '19 at 05:43
  • @Troy: which version? what OS? – sophros Apr 25 '19 at 09:58
  • @sophros my bad, I didn't realize the earlier comments was talking about code cells. I've deleted my original comment. – Troy Apr 25 '19 at 11:10
  • 1
    Ctrl - C / Ctrl - V work, but it takes about half minutes for the pasted content to show up in the new notebook, with Jupyter 6.0 on Ubuntu 18.04 – Yu Shen Oct 16 '19 at 14:38
  • I just found out that sometimes when you hit Ctrl-C, it really forces you to the edit mode. At this time, the cell will turn green. Then you can just hit "enter" and "Ctrl-C" again if the cell did not turn to green, then you are ready to past. – shane Nov 25 '19 at 14:57
  • Ctrl+C and Ctrl+V didn't work on Google Chrome, but worked on Microsoft Edge. On Google Chrome, Ctrl+C just puts you into edit mode. – Princy May 12 '20 at 18:56
  • it isn't working to me in Jupyter Notebook 7.0.2 anymore, it not even appears in Command Pallete, or any Menu's item option. Only the 'C' hotkey works, which only copies cells within same notebook. – miguelfg Aug 24 '23 at 14:28
16

With jupyter 5.0.0, copy paste of one or many cells from one notebook to another works with Cmd C Cmd V (Mac).

For copying many cells together, select the first one then the last one with shift arrow (up or down).

The tool bar does not work for this purpose.

See also https://github.com/jupyter/notebook/issues/2336

Pierre ALBARÈDE
  • 413
  • 4
  • 10
  • 6
    Ctrl-C/Ctrl-V on linux. And when you paste make sure you're in Command mode (Blue line on the left of the cell), otherwise it'll collapse all copied cells into one if you're in Edit mode (Green line). Hit Esc to switch between modes. – stason Aug 09 '18 at 02:26
  • 3
    NOTE: currently (jupyter 6.0.0) on Mac+chrome using shift-click to select the cells then cmd-C does NOT work!! Using shift-down-arrow however does (odd behaviour, but there you are!). Visually, shift-click and shift-down-arrow seem identical, but apparently not... – drevicko Aug 27 '19 at 03:55
3

I have not done it myself though, but general practice is to avoid doing it as it can disturb the Cell JSON. It was not even possible until a few versions before. Recent Github posts has made it possible to do so though. Copy paste the cell in question to a code editor such as Atom or Sublime Text, make the changes you want to do and then paste it into the new Jupyter notebook. It should work.

3

For windows-
Use Ctrl + Shift + C to copy cells after selecting them using shift + arrow keys.

Then, switch to the notebook to which you want to copy the selected cells and go to command mode in it by pressing Esc key. Then, use Ctrl + Shift + V to paste the cells in that notebook.

Note- I have not tested this on Linux but should work just as the procedure above.

1

VSCode can open and execute jupyter notebooks.

In the same software it is also possible to cut/copy and paste from one notebook to another (something that I didn't manage to do with jupyter notebook or lab).

It saved me a lot of time.

Vincenzooo
  • 2,013
  • 1
  • 19
  • 33
0

In JupyterLab, you can view two notebooks arranged as panes side-by-side. (Or even two views of the same notebook.)
Then you can select a cell or continuous range of them. When they are highlighted go to the top cell and click and drag over to the other notebook to copy them.

Wayne
  • 6,607
  • 8
  • 36
  • 93
-6

You can download the cell content as .py file from jupier and then you can copy and paste wherever you want

Siva Kumar
  • 459
  • 4
  • 6