'Correct way to package a .ipynb as an executable file

Background - I have created a Python script that has many dependencies; the script calls an API, returns some data as a JSON, before its saved in a pandas df and then written to an .xlsx file using xlsxwriter.

Issue - the script is written in Jupyter Lab and therefore is currently a .ipynb file. I am trying to turn this script into the most effective executional script, which I can run daily (using Windows Scheduler). In JupyterLab, I have tried to File --> Save and Export Notebook As...'. and that works if the script is simple, like input("Type something").

However if I try and save a more complex script with many dependencies in the same way, the 'executable file' will open then quickly close, without giving me the opportunity to see what went wrong (the script runs fine in JupyterLab in .ipbny format) I should say that 'complex script' has a progress bar and other elements which should print to the console for an extended period of time.

Help - what is the correct way to make larger python scripts (with lots of dependencies) executable? And are there additional steps taken, when dealing with large scripts? Here are the dependencies that my code replies on -

# Importing depedencies
from configparser import ConfigParser
import datetime as date
import datetime as dt
import datetime
from datetime import timedelta
from datetime import date
import itertools
import pandas as pd
from pandas import json_normalize
import requests as requests
from requests.auth import HTTPBasicAuth
import time
import json
import jsonpath_ng as jp
import xlsxwriter
import enlighten


Solution 1:[1]

The easiest way I can think of is converting it to .py just using pyinstaller. That is the traditional way of doing it.

pyinstaller --onefile main.py

Copy the .exe where all your other files/dependencies are.

And add:

if getattr(sys, 'frozen', False):
   application_path = os.path.dirname(sys.executable)
elif __file__:
   application_path = os.path.dirname(__file__)

Add the application_path to all your paths

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yashoraj Agarwal