117

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

7 Answers 7

108

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)

10
  • 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, 2017 at 8: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, 2019 at 15:13
  • 2
    This does not work in Firefox (see: bug)
    – sophros
    Apr 9, 2019 at 5:43
  • @Troy: which version? what OS?
    – sophros
    Apr 25, 2019 at 9:58
  • 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, 2019 at 14:38
17

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

2
  • 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 9, 2018 at 2: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, 2019 at 3: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
  • I understand your recommendation, but anyway I would like to know how this is possible Oct 28, 2016 at 16:43
  • This request has been closed in Github, so it pretty much means it has been resolved. You can try this link and see if you can code up something like this: Oct 28, 2016 at 17:29
  • 2
    I have already read it before asking. They are saying that the problem is solved without telling how. Oct 28, 2016 at 17:43
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.

2

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.

1
  • note that, as pointed out in other answers, this capability was added also in jupyter and jupyterlab.
    – Vincenzooo
    Sep 26 at 10: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.

-7

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.