0

Due to optimization issues, I had to transfer my code to pure Python form in order to implement multiprocessing.Now I have a Python script that runs as expected when executed by Visual Studio Code. I want to find a way to call that script from Jupyter Notebook, after I pass inside some arguments, execute the program the same way that happens in VSCode and transfer the results back to Jupyter.

Is there a way to do that?

Edit: Although your answers have been really helpful and I managed to do what I first envisioned, a huge issues ensued. To be specific, in order to implement multiprocessing, I need the condition

if name = 'main': (there are underscores here,instead of being bold)

and thus when I run the script using jupyter it evaluates to False , and so multiprocessing never takes place.Is there a way around it?

Grk38
  • 1
  • 1
  • 1
    Perhaps you could wrap the script in a function, add `__init__.py` into the folder where the notebook is and import the functions as you would from a package? – Roman Luštrik May 16 '23 at 07:54
  • there is an excellent question and answer explaining how to do this [here](https://stackoverflow.com/questions/42163470/how-to-execute-a-py-file-from-a-ipynb-file-on-the-jupyter-notebook). As noted above though, it's probably better to turn it into a function and import that, if it's possible. – Hoodlum May 16 '23 at 07:58

1 Answers1

0

Well one of the way i know if open jupyter notebook terminal and run your Python scripts in the terminal like you would in your local terminal.

Another way which i have heard is using the jupyterlab-executor :

pip install jupyterlab-executor