How to run a Python script within a Jupyter Notebook?

Learn how to run a Python script in a Jupyter Notebook with our easy-to-follow guide. Perfect for beginners and experts in Python programming.

Hire Top Talent

Are you a candidate? Apply for jobs

Quick overview

The problem here is about executing a Python script within a Jupyter Notebook. Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. A Python script is a program written in Python. The user wants to know how to run this script within the Jupyter Notebook environment. This involves understanding how to import and execute Python files in Jupyter Notebook.

Hire Top Talent now

Find top Data Science, Big Data, Machine Learning, and AI specialists in record time. Our active talent pool lets us expedite your quest for the perfect fit.

Share this guide

How to run a Python script within a Jupyter Notebook: Step-by-Step guide

Step 1: Install Jupyter Notebook
If you haven't installed Jupyter Notebook on your computer, you can do so by using pip, which is a package manager for Python. Open your command prompt or terminal and type the following command:

pip install jupyter

Wait for the installation to complete.

Step 2: Launch Jupyter Notebook
Once you have Jupyter Notebook installed, you can launch it by typing the following command in your terminal or command prompt:

jupyter notebook

This will open Jupyter Notebook in your default web browser.

Step 3: Create a New Python Notebook
In the Jupyter Notebook interface, click on the "New" button and select "Python 3" or the version of Python you have installed. This will create a new Python notebook where you can write and run your Python scripts.

Step 4: Write Your Python Script
In the new Python notebook, you will see a cell where you can write your Python script. Click on the cell and start typing your Python code.

Step 5: Run Your Python Script
Once you have written your Python script, you can run it by clicking on the "Run" button at the top of the Jupyter Notebook interface. Alternatively, you can use the keyboard shortcut Shift + Enter to run the script.

Step 6: View the Output
After running your Python script, the output will be displayed directly below the cell where you wrote your script. If there are any errors in your script, they will also be displayed in this area.

Remember to save your work regularly by clicking on the "Save" button or using the keyboard shortcut Ctrl + S.

Join over 100 startups and Fortune 500 companies that trust us

Hire Top Talent

Our Case Studies

CVS Health, a US leader with 300K+ employees, advances America’s health and pioneers AI in healthcare.

AstraZeneca, a global pharmaceutical company with 60K+ staff, prioritizes innovative medicines & access.

HCSC, a customer-owned insurer, is impacting 15M lives with a commitment to diversity and innovation.

Clara Analytics is a leading InsurTech company that provides AI-powered solutions to the insurance industry.

NeuroID solves the Digital Identity Crisis by transforming how businesses detect and monitor digital identities.

Toyota Research Institute advances AI and robotics for safer, eco-friendly, and accessible vehicles as a Toyota subsidiary.

Vectra AI is a leading cybersecurity company that uses AI to detect and respond to cyberattacks in real-time.

BaseHealth, an analytics firm, boosts revenues and outcomes for health systems with a unique AI platform.

Latest Blogs

Experience the Difference

Matching Quality

Submission-to-Interview Rate

65%

Submission-to-Offer Ratio

1:10

Speed and Scale

Kick-Off to First Submission

48 hr

Annual Data Hires per Client

100+

Diverse Talent

Diverse Talent Percentage

30%

Female Data Talent Placed

81