This shell script quickly converts Jupyter Notebook files (.ipynb
) into clean Python scripts (.py
), removing unnecessary cell notations (# In[ ]:
) and formatting the code with black
for a polished final product. Perfect for integrating your Jupyter work into your development projects!
Before using the script, ensure you have the following installed:
pip install jupyter nbconvert black
-
Download the Script:
- Save
jupyter_converter.sh
to your local machine.
- Save
-
Make It Executable:
-
In your terminal, navigate to the script's directory and run:
chmod +x jupyter_converter.sh
-
-
Convert Your Notebook:
-
Run the script with your
.ipynb
file:./jupyter_converter.sh <notebook.ipynb>
-
Example:
./jupyter_converter.sh example_notebook.ipynb
-
-
Get Your Cleaned Script:
- The output will be a formatted Python file named
example_notebook.py
.
- The output will be a formatted Python file named
Convert data_analysis.ipynb
to a Python script:
./jupyter_converter.sh data_analysis.ipynb
You'll find data_analysis.py
in the same directory, ready to use.
command not found
: Make surejupyter
andblack
are installed and in your PATH.No such file or directory
: Ensure the notebook file exists where you specified.
Have feedback or want to contribute? Feel free to open an issue or submit a pull request!
Happy coding! 🚀😊