65.2k views
1 vote
How to run a python script in jupyter notebook

User Adirael
by
8.2k points

1 Answer

6 votes

Final answer:

To run a Python script in Jupyter Notebook, open a notebook from the Jupyter dashboard, use the %run command in a cell followed by your script name.

Step-by-step explanation:

To run a Python script in a Jupyter Notebook, you first need to ensure you have Jupyter installed and then start a notebook. Here's a simple guide: Open your Jupyter Notebook interface by running jupyter notebook in your command line or terminal.

In the Jupyter Notebook dashboard, navigate to the directory where your Python script is located and open a new notebook by clicking on 'New' > 'Python X'. In a new cell within the notebook, use the command %run script_name.py to execute the Python script. Replace 'script_name.py' with the actual name of your Python script.

Alternatively, you can use !python script_name.py which will also execute the script in the context of the current Jupyter Notebook shell. Both methods allow for the integration of Python scripts within a Jupyter Notebook, offering an interactive environment to run, test, and debug your code.

User Berk Kurkcuoglu
by
8.8k points