The Wayback Machine - https://web.archive.org/web/20240910062813/https://www.geeksforgeeks.org/run-python-file-in-vscode/
Open In App

Run Python File In Vscode

Last Updated : 05 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Visual Studio Code (VSCode) is a popular and versatile code editor that supports Python development with various features and extensions. In this article, we will see how to run Python files in VsCode.

Run Python Script in VScode

Below is the step-by-step procedure by which we can run the basic Python Script in VScode:

Step 1: Installation

Install the following libraries before starting.

Step 2: Install Python Extension

Launch VSCode, go to the Extensions view (you can press Ctrl+Shift+X), and search for “Python.” Install the one provided by Microsoft, which is the official Python extension.

Screenshot2024-01-26203254-ezgifcom-resize

Step 3: Create a Python File

Create a new Python file or open an existing one. For example, let’s create a file named basic.py with the following content:

Python3




print("Hello GeeksforGeeks")


Output:

Screenshot-2024-01-26-203648

Step 4: Select Python Interpreter

In the bottom-right corner of the VSCode window, click on the interpreter version (it might say “Select Python Interpreter”). Choose the Python interpreter you want to use for this project.

ezgifcom-crop

Step 5: Run the Python File

Using Right Click

Right-click on the editor or use the run button provided on thhe left corner of VScode to run the Python file. You should see the output in the terminal at the bottom of the VSCode window.

Screenshot2024-01-26204429-ezgifcom-png-to-webp-converter

Using Play Button

We can run our Python program inside the Python file using the Play button given on the right of the Visual Studio Code as given in the below picture.

Screenshot-2024-02-03-194202

Using Specifiying the Path in the Terminal

We can also run the Python file by specifying the path in the terminal as shown in the below picture.

ezgifcom-resize

Output in Terminal

Screenshot-2024-01-26-204512



Similar Reads

How to Setup VSCode with C, C++ and Python for Competitive Programming
VSCode is a Text editor that provides support for development operations and version control systems. It provides tools for a user to build hassle-free codes. VSCode can be downloaded and installed from visualstudio.com This article will show you how to, fetch test cases directly from the browser without copy-pasting and run them in VSCode with jus
5 min read
How to debug a python module in VSCode
Debugging is an essential part of the development process, allowing developers to inspect their code, understand its behavior, and identify and fix issues. Visual Studio Code (VSCode) is a powerful, free code editor that offers robust debugging capabilities for Python. This article will guide you through the process of setting up and using VSCode t
7 min read
How to Fix "Can't Import Numpy in VSCode" in Python?
NumPy is a general-purpose array-processing Python library that provides handy methods and functions for working with n-dimensional arrays. NumPy is short for “Numerical Python” and offers various computing tools such as comprehensive mathematical functions and linear algebra routines. VSCode (Visual Studio Code) is a text editor that supports deve
4 min read
How to Format JSON in VSCode
VSCode offers multiple ways to format JSON files, making it easy for developers to choose the method that best suits their workflow. A well-formatted JSON file is easier to read, understand, and debug, especially when working with complex data structures. Formatting JSON in VSCodeLet us see these ways one by one. JSON formatting refers to the way J
2 min read
Locating and Modifying VSCode settings.json
Visual Studio Code (VSCode) is a popular code editor known for its customizability. This customizability is mainly due to the settings.json file, where we can configure the editor to our preferences. The settings.json file in Visual Studio Code (VS Code) plays a crucial role in customizing the code editor to fit individual needs. We can tailor VS C
3 min read
How to run Python script directly in Kivy file?
Kivy is a platform-independent GUI tool in Python. It can run on Android, IOS, Linux and Windows, etc. This is the only GUI library from python which can independently run on the android device even we can use it on Raspberry pi also. It is an open-source Python library for the rapid development of applications that make use of innovative user inte
3 min read
How to run multiple Python file in a folder one after another?
In this article, we will discuss how to run multiple python files in a folder one after another. There can be many ways to this task, here, we will discuss a few of them. For doing this program, we have to create some python files in one folder and give some names to that folder. The content inside a.py file: print("a") The content inside b.py file
3 min read
Python - Get file id of windows file
File ID is a unique file identifier used on windows to identify a unique file on a Volume. File Id works similar in spirit to a inode number found in *nix Distributions. Such that a fileId could be used to uniquely identify a file in a volume. We would be using an command found in Windows Command Processor cmd.exe to find the fileid of a file. In o
3 min read
How to save file with file name from user using Python?
Prerequisites: File Handling in PythonReading and Writing to text files in Python Saving a file with the user's custom name can be achieved using python file handling concepts. Python provides inbuilt functions for working with files. The file can be saved with the user preferred name by creating a new file, renaming the existing file, making a cop
5 min read
How to convert PDF file to Excel file using Python?
In this article, we will see how to convert a PDF to Excel or CSV File Using Python. It can be done with various methods, here are we are going to use some methods. Method 1: Using pdftables_api Here will use the pdftables_api Module for converting the PDF file into any other format. It's a simple web-based API, so can be called from any programmin
2 min read
How to convert CSV File to PDF File using Python?
In this article, we will learn how to do Conversion of CSV to PDF file format. This simple task can be easily done using two Steps : Firstly, We convert our CSV file to HTML using the PandasIn the Second Step, we use PDFkit Python API to convert our HTML file to the PDF file format. Approach: 1. Converting CSV file to HTML using Pandas Framework. P
3 min read
How to create a duplicate file of an existing file using Python?
In this article, we will discuss how to create a duplicate of the existing file in Python. Below are the source and destination folders, before creating the duplicate file in the destination folder. After a duplicate file has been created in the destination folder, it looks like the image below. For automating of copying and removal of files in Pyt
5 min read
Python - Copy all the content of one file to another file in uppercase
In this article, we are going to write a Python program to copy all the content of one file to another file in uppercase. In order to solve this problem, let's see the definition of some important functions which will be used: open() - It is used to open a file in various modes like reading, write, append, both read and write.write() - It is used t
2 min read
How to convert a PDF file to TIFF file using Python?
This article will discover how to transform a PDF (Portable Document Format) file on your local drive into a TIFF (Tag Image File Format) file at the specified location. We'll employ Python's Aspose-Words package for this task. The aspose-words library will be used to convert a PDF file to a TIFF file. Aspose-Words: Aspose-Words for Python is a pot
3 min read
Run Python script from Node.js using child process spawn() method
Node.js is one of the most adopted web development technologies but it lacks support for machine learning, deep learning and artificial intelligence libraries. Luckily, Python supports all these and many more other features. Django Framework for Python can utilize this functionality of Python and can provide support for building new age web applica
3 min read
Python | Making program run faster
As we know, Python programming language is a bit slow and the target is to speed it up without the assistance of more extreme solutions, such as C extensions or a just-in-time (JIT) compiler.While the first rule of optimization might be to "not do it", the second rule is almost certainly "don’t optimize the unimportant." To that end, if the program
8 min read
Run python script from anywhere in linux
In Linux, there is a way to execute python files from anywhere. This can be done by typing several commands in the terminal. Prerequisite: Basic Shell Commands in Linux Basics of python Steps: At first, open the terminal and go to the home directory. To go the home directory type the following command. cd ~ Create a folder and a python script insid
2 min read
Python IMDbPY – Getting run time of the series
In this article we will see how we can get the run time of the series, run time is basically the time for which how long each episode run is of series basically run time is the length i.e how long each episode is in minutes. In order to get this we have to do the following - 1. Get the series details with the help of get_movie method 2. As this obj
2 min read
Run Python Script using PythonShell from Node.js
Nowadays Node.js is the most attractive technology in the field of backend development for developers around the globe. And if someone wishes to use something like Web Scraping using python modules or run some python scripts having some machine learning algorithms, then one need to know how to integrate these two. We are going to get some data of a
3 min read
Python IMDbPY – Getting Series Run times as XML
In this article we will see how we can get the series run times information(info-set) in the XML format. Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. Series object contains all the information about all the episodes and seasons
2 min read
Run shell command from GUI using Python
In this article, we are going to discuss how we can create a GUI window that will take Operating System commands as input and after executing them, displays the output in a pop-up window. Modules Required: PyAutoGui: It is a module in python which is used to automate the GUI and controls the mouse and keyboard. It is an external module, it can be i
2 min read
How to run same function on multiple threads in Python?
In a large real-world application, the modules and functions have to go through a lot of input and output-based tasks like reading or updating databases, communication with different micro-services, and request-response with clients or peers. These tasks may take a significant amount of time to complete. The time taken in serving a request and resp
3 min read
Google Cloud Platform - Running Different Versions of Python on Google Cloud Run
Problem Statement: Rinki works for StoreCraft(Say) as a site reliability engineer, where she's on-call maintaining their custom storefront. StoreCraft's systems are developed in-house in Python and have been running on virtual machines for years, a set up that evolved as StoreCraft's businesses did. These virtual machines use slightly different ver
3 min read
How to run bash script in Python?
If you are using any major operating system, you are indirectly interacting with bash. If you are running Ubuntu, Linux Mint, or any other Linux distribution, you are interacting with bash every time you use the terminal. Suppose you have written your bash script that needs to be invoked from python code. The two common modules for interacting with
2 min read
Schedule a Python Script to Run Daily
In this article, we are going to see how to schedule a Python Script to run daily. Scheduling a Python Script to run daily basically means that your Python Script should be executed automatically daily at a time you specify. Preparing the Python Script.Create a Python Script that you want to schedule. In our example, we made a simple Python Script
3 min read
How to Run JavaScript from Python ?
In this article, we'll discuss how to run a javascript file with Python. For this, we'll use the JS2PY(Javascript Runtime in Pure Python) Python module. JS2PY works by translating JavaScript directly into Python. It indicates that you may run JS directly from Python code without installing large external engines like V8. To use the module it first
2 min read
How To Connect and run SQL queries to a PostgreSQL database from Python
This article focus on connecting to a PostgreSQL database from Python. Installation:Install PostgreSQL, If you haven't installed it.We need to install the psycopg2 library to connect to a PostgreSQL database. Open the command prompt and run the below command to install psycopg2pip3 install psycopg2Creating a Database You can create a Database in 2
2 min read
How to run Scrapy spiders in Python
In this article, we are going to discuss how to schedule Scrapy crawl execution programmatically using Python. Scrapy is a powerful web scraping framework, and it's often necessary to schedule the execution of a Scrapy crawl at specific intervals. Scheduling Scrapy crawl execution programmatically allows you to automate the process of scraping data
5 min read
Run function from the command line In Python
Python is a flexible programming language with a wide range of uses that one of Python’s most useful ones is its ability to execute functions from the command line. Especially this feature is very useful when it comes to automation and scripting etc. In this article, I’ll explain how to execute a Python function from the command line. Defining a Fu
4 min read
How to Run a Python Script
Python scripts are Python code files saved with a .py extension. You can run these files on any device if it has Python installed on it. They are very versatile programs and can perform a variety of tasks like data analysis, web development, etc. You might get these Python scripts if you are a beginner in Python so in this discussion, we will explo
6 min read