Skip to content

Mobasheera/PyDocx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Convert Jupyter Notebooks to Word Documents

This repository contains a Python script (convert_ipynb_to_docx.py) that automates the conversion of all Jupyter Notebook (.ipynb) files in the current directory into Word documents (.docx).

Prerequisites

Before running the script, make sure you have the following installed:

  1. Python (3.7 or newer)

  2. Jupyter Notebook

    • Install Jupyter Notebook using pip:
      pip install notebook
  3. Pandoc

    • Download and install Pandoc from https://pandoc.org/installing.html.
    • Ensure Pandoc is added to your system's PATH so it can be used from the terminal.
    • Add the install location in yout system's PATH its usually ‪C:\Program Files\Pandoc\pandoc.exe

Steps to Run the Script

Follow these steps to use the script:

  1. Clone the Repository Clone this repository to your local machine:

    git clone <repository_url>
    cd <repository_name>
    1. Install Required Python Libraries Install the nbconvert package, which is used for converting .ipynb to .md:
    pip install nbconvert
  2. Place the Jupyter Notebooks in the Directory Ensure all the .ipynb files you want to convert are in the same directory as the script (convert_ipynb_to_docx.py).

  3. Run the Script Run the script from the terminal:

    python convert_ipynb_to_docx.py
  4. View the Output

    • The script will generate .docx files for each .ipynb file in the current directory.
    • The .docx files will be saved in the same directory as the script.
  5. Clean Up (Optional)

    • The script automatically removes intermediate .md files after the conversion.
    • If you want to keep the .md files, edit the script and comment out the os.remove(md_file) line.

Example

Suppose your directory contains the following files:

convert_ipynb_to_docx.py
notebook1.ipynb
notebook2.ipynb

After running the script, your directory will look like this:

convert_ipynb_to_docx.py
notebook1.ipynb
notebook2.ipynb
notebook1.docx
notebook2.docx

Troubleshooting

  • Command not found: pandoc

    • Ensure Pandoc is installed and added to your system's PATH.
    • You can test this by running:
      pandoc --version
  • Missing Jupyter or nbconvert

    • Ensure Jupyter is installed using:
      pip install notebook
  • Script Errors

    • Make sure your .ipynb files are not corrupted or empty.
    • If you encounter specific errors, please open an issue in this repository.

Happy converting!

About

Convert .ipynb files to .docx

Resources

License

Stars

Watchers

Forks

Contributors

Languages