4

I was wondering if their is anyway to go through and make copies of each .ipynb file in a folder and then change that file to .py. I want to keep the .ipynb files but I would like to have a .py file as well. I know how to do it manually but would like a way to do it automatically for each file in a specified directory.

1
  • check this out, I think it'll help Commented Aug 21, 2017 at 17:34

4 Answers 4

6

Just try this at Cmd prompt inside that folder.

jupyter nbconvert *.ipynb --to script

Converts all .ipynb files to .py and retains all .ipynb files as well.
Hope it helps

For more details, Check this link as well Save .ipynb to .py automatically on saving notebook

Sign up to request clarification or add additional context in comments.

Comments

4

find . -name "*.py" -exec ipython nbconvert --to=python {} \; should work on Linux.

1 Comment

exec does not work
4
import os

directory = 'ipynb PATH'

for subdir, dirs, files in os.walk(directory):
    for file in files:
        if os.path.splitext(file)[1] == '.ipynb':
            exe_command = 'jupyter nbconvert "{}" --to python'.format(''.join(os.path.join(subdir, file)))
            
            # print the command`enter code here`
            # print (exe_command)
            
            os.system(exe_command)
            
            # Delete the file 
            # os.remove(''.join(os.path.join(subdir, file)))
        else:
            continue

2 Comments

Converts all .ipynb files in a directory to .py you can delete the files that been converted, you should pip install nbconvert before
amazing solution- helped to convert all my ipynb into py
0

To convert all .ipynb files to .py in a directory structure recursively you may execute

find . -name "*.ipynb" -exec jupyter nbconvert --to script {} \;

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.