Skip to content
Home » Python Ide Visual Studio | Jupyter Notebooks

Python Ide Visual Studio | Jupyter Notebooks

How to Setup Python on Microsoft Visual Studio 2022 | Amit Thinks

Create a virtual environment

A best practice among Python developers is to use a project-specific

virtual environment

. Once you activate that environment, any packages you then install are isolated from other environments, including the global interpreter environment, reducing many complications that can arise from conflicting package versions. You can create non-global environments in VS Code using Venv or Anaconda with Python: Create Environment.

Open the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)), start typing the Python: Create Environment command to search, and then select the command.

The command presents a list of environment types, Venv or Conda. For this example, select Venv.

The command then presents a list of interpreters that can be used for your project. Select the interpreter you installed at the beginning of the tutorial.

After selecting the interpreter, a notification will show the progress of the environment creation and the environment folder (

/.venv

) will appear in your workspace.

Ensure your new environment is selected by using the Python: Select Interpreter command from the Command Palette.

Note: For additional information about virtual environments, or if you run into an error in the environment creation process, see Environments.

Install Python and the Python extension

The tutorial guides you through installing Python and using the extension. You must install a Python interpreter yourself separately from the extension. For a quick install, use Python from python.org and install the extension from the VS Code Marketplace.

Note: To help get you started with Python development, you can use the Python profile template that includes useful extensions, settings, and Python code snippets.

Once you have a version of Python installed, select it using the Python: Select Interpreter command. If VS Code doesn’t automatically locate the interpreter you’re looking for, refer to Environments – Manually specify an interpreter.

You can configure the Python extension through settings. Learn more in the Python Settings reference.

Windows Subsystem for Linux: If you are on Windows, WSL is a great way to do Python development. You can run Linux distributions on Windows and Python is often already installed. When coupled with the WSL extension, you get full VS Code editing and debugging support while running in the context of WSL. To learn more, go to Developing in WSL or try the Working in WSL tutorial.

How to Setup Python on Microsoft Visual Studio 2022 | Amit Thinks
How to Setup Python on Microsoft Visual Studio 2022 | Amit Thinks

Jupyter notebooks

To enable Python support for Jupyter notebook files (

.ipynb

) in VS Code, you can install the Jupyter extension. The Python and Jupyter extensions work together to give you a great Notebook experience in VS Code, providing you the ability to directly view and modify code cells with IntelliSense support, as well as run and debug them.

You can also convert and open the notebook as a Python code file through the Jupyter: Export to Python Script command. The notebook’s cells are delimited in the Python file with

#%%

comments, and the Jupyter extension shows Run Cell or Run Below CodeLens. Selecting either CodeLens starts the Jupyter server and runs the cell(s) in the Python interactive window:

You can also connect to a remote Jupyter server to run your notebooks. For more information, see Jupyter support.

Questions and answers

Q. Is Python support available with Visual Studio for Mac?

A. Visual Studio for Mac isn’t currently supported. For more information, see What’s happening to Visual Studio for Mac? Visual Studio Code on Windows, Mac, and Linux works well with Python through available extensions.

Q. What can I use to build UI with Python?

A. The main offering in this area is the Qt Project with bindings for Python known as PySide (the official binding) (also see PySide downloads) and PyQt. Python support in Visual Studio doesn’t include any specific tools for UI development.

Q. Can a Python project produce a stand-alone executable?

A. Python is generally an interpreted language, where code is run on demand in a suitable Python-capable environment such as Visual Studio and web servers. Visual Studio doesn’t currently provide the means to create a stand-alone executable, which essentially means a program with an embedded Python interpreter. However, the Python community offers different means to create executables as described on StackOverflow. CPython also supports being embedded within a native application, as described on the blog post, Using CPython’s embeddable zip file.

Visual Studio 2022 (Python Getting Started)
Visual Studio 2022 (Python Getting Started)

Enhance completions with AI

GitHub Copilot is an AI-powered code completion tool that helps you write code faster and smarter. You can use the GitHub Copilot extension in VS Code to generate code, or to learn from the code it generates.

GitHub Copilot provides suggestions for languages beyond Python and a wide variety of frameworks, including JavaScript, TypeScript, Ruby, Go, C# and C++.

You can learn more about how to get started with Copilot in the Copilot documentation.

Phản hồi

Gửi và xem ý kiến phản hồi dành cho

Reviewed and fact-checked by Sayantoni Das

An integrated development environment (IDE) refers to a software application that offers computer programmers with extensive software development abilities. IDEs most often consist of a source code editor, build automation tools, and a debugger. Most modern IDEs have intelligent code completion. In this article, you will discover the best Python IDEs currently available and present in the market.

How to set up Python on Visual Studio Code
How to set up Python on Visual Studio Code

Feedback

Submit and view feedback for

Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: Finding the Perfect Python Code Editor

Writing Python using IDLE or the Python shell is great for smaller tasks, but those tools quickly turn larger programming projects into frustrating pits of despair. Using an IDE, or even just a good dedicated code editor, makes coding fun—but which one is best for you?

Fear not, gentle reader! Here, you’ll demystify the myriad choices available to you. What works best for you will ultimately depend on you and your process, but you’ll get the pros and cons of each option so that you can make an informed decision.

To make things easier, you’ll break your list into two broad categories of tools: the ones built exclusively for Python development and the ones built for general development that you can use for Python. You’ll explore some Whys and Why Nots for each. Lastly, none of these options are mutually exclusive, so you can try them out on your own with very little penalty.

Join Now: Click here to join the Real Python Newsletter and you’ll never miss another Python tutorial, course update, or post.

But first, what are IDEs and code editors?

Next steps

  • Python Hello World tutorial – Get started with Python in VS Code.
  • Editing Python – Learn about auto-completion, formatting, and refactoring for Python.
  • Basic Editing – Learn about the powerful VS Code editor.
  • Code Navigation – Move quickly through your source code.
  • Django tutorial
  • Flask tutorial

Python in Visual Studio Code

Visual Studio Code is a free source code editor that fully supports Python and useful features such as real-time collaboration. It’s highly customizable to support your classroom the way you like to teach.

“Visual Studio Code is the best balance of authenticity and accessibility… Visual Studio Code doesn’t feel ‘fake’, it’s what real software developers use. Plus, Visual Studio Code works on every OS!” – Professor Zachary Dodds from Harvey Mudd College

Read below for recommendations for extensions, settings, and links to free lessons that you can use in your classes.

How to Run Python in Visual Studio Code on Windows 10 [2022] | Run Sample Python Program
How to Run Python in Visual Studio Code on Windows 10 [2022] | Run Sample Python Program

Autocomplete and IntelliSense

The Python extension supports code completion and IntelliSense using the currently selected interpreter. IntelliSense is a general term for a number of features, including intelligent code completion (in-context method and variable suggestions) across all your files and for built-in and third-party modules.

IntelliSense quickly shows methods, class members, and documentation as you type. You can also trigger completions at any time with ⌃Space (Windows, Linux Ctrl+Space). Hovering over identifiers will show more information about them.

Intro to CS at Harvey Mudd College

Professor Zachary Dodds is a Computer Science professor at Harvey Mudd College who teaches several introductory classes both for students new to Computer Science and students from a non-Computer Science background. He co-created the popular introduction to Computer Science class CS5, which attracts students from all backgrounds to develop programming and problem-solving skills and to build “a coherent, intellectually compelling picture of Computer Science”. The class is taught with Python and uses VS Code as the recommended editor.

Why Visual Studio Code?

Professor Dodds has been recommending and using Visual Studio Code in his classes since it debuted in 2015.

“Visual Studio Code is the best balance of authenticity and accessibility… Visual Studio Code doesn’t feel ‘fake’, it’s what real software developers use. Plus, Visual Studio Code works on every OS!”

VS Code runs on Windows, macOS, Linux, and even Chromebooks.

Classroom settings

Since VS Code is easy to customize, Professor Dodds is able to tailor the editor for his students, preferring to hide IntelliSense, or code completion suggestions, so they can learn from what they type and reinforce the conceptual models being built.

Here are the settings his students use:


"editor.quickSuggestions": false, "editor.acceptSuggestionOnCommitCharacter": false, "editor.suggest.filterGraceful": true, "editor.suggestOnTriggerCharacters": false, "editor.acceptSuggestionOnEnter": "on", "editor.suggest.showIcons": false, "editor.suggest.maxVisibleSuggestions": 7, "editor.hover.enabled": false, "editor.hover.sticky": false, "editor.suggest.snippetsPreventQuickSuggestions": false, "editor.parameterHints.enabled": false, "editor.wordBasedSuggestions": "matchingDocuments", "editor.tabCompletion": "on", "extensions.ignoreRecommendations": true, "files.autoSave": "afterDelay",

You can find the most up-to-date settings on his course website: CS5 – Python Tips.

Integrated Terminal

Professor Dodds also utilizes the built-in terminal heavily in his class as an introduction to running programs from the command line and navigating around their machine all within Visual Studio Code. He appreciates how “the built-in terminal panel does not try to automate too much (which, if it did, would deprive newcomers of the experience of the information-flow that’s going on).”

In the video below, the student does all of their command line and coding work in one place, such as installing Python libraries, while working on Lab 3 from the CS5 class:

Thank you, Professor Dodds, for sharing your story! If you’re interested in using VS Code to teach Python in your classes, you can get started with the Python Education Extension Pack below!

How to setup Python for VSCode in 2023 in 5mins! | Install Python and Setup VSCode for Windows 10
How to setup Python for VSCode in 2023 in 5mins! | Install Python and Setup VSCode for Windows 10

Configuring Linting and Formatting in VSCode

Linting

Linting highlights the problems in the Python source code and provides us with suggestions. It generally highlights syntactical and stylistic issues. Linting helps you identify and correct coding issues that can lead to errors.

You can select the linting method by selecting Python: Select Linter command in the command palette (Ctrl+Shift+P). You can also manually enable the linting method in settings.

Select linting method

In our case, we have selected the flake8 method. You can also review the list of available linting methods.

  • Enable/ Disable Linting: select Python: Enable/Disable Linting in command palette.
  • Run Linting: command palette (Ctrl+Shift+P) > Python: Run Linting.

Fixing the error

After running the Python linter, you will see the issues with the suggestions.

Note: Enabling a different linter will prompt you to install the required Python package.

Formatting

Formatting makes code readable. It follows specific rules for line spacing, indents, spacing around operators, and closing brackets. The Python extension supports three Python formatting methods: autopep8, black, or yapf.

By reading about PEP-8: Python Naming Conventions & Code Standards, you can learn Python’s style guide and formatting rules.

Select the Python formatter

To access the formatting option, we have to open the settings panel by going to Preferences -> Settings or using the keyboard shortcut: Ctrl +,. After that, type “python formatting provider” in the search bar and select “black” from the dropdown menu.

Configure Python formatter

For formatting the Python file on save, we have to search for format on save in the Settings and enable the Editor: Format on Save option.

Introduction to IDEs and Code Editors

An integrated development environment (IDE) is a program dedicated to software development. As the name implies, IDEs integrate several tools specifically designed for software development. These tools usually include:

  • An editor designed to handle code (with, for example, syntax highlighting and auto-completion)
  • Build, execution, and debugging tools
  • Some form of source control

Most IDEs support many different programming languages and contain many more features. They can, therefore, be large and take time to download and install. You may also need advanced knowledge to use them properly.

In contrast, a dedicated code editor can be as simple as a text editor with syntax highlighting and code formatting capabilities. Most good code editors can execute code and control a debugger. The very best ones interact with source control systems as well. Compared to an IDE, a good dedicated code editor is usually smaller and quicker, but often less feature rich.

First Python App in Visual Studio 2022 | Getting Started
First Python App in Visual Studio 2022 | Getting Started

Rich editing, IntelliSense, and code comprehension

Visual Studio provides a first-class Python editor, including syntax coloring, autocomplete across all your code and libraries, code formatting, signature help, refactoring, linting, and type hints. Visual Studio also provides unique features like class view, Go to Definition, Find All References, and code snippets. Direct integration with the Interactive window helps you quickly develop existing Python code in a file.

For more information:

Python profile template

Profiles let you quickly switch your extensions, settings, and UI layout depending on your current project or task. To help you get started with Python development, you can use the Python profile template, which is a curated profile with useful extensions, settings, and snippets. You can use the profile template as is or use it as a starting point to customize further for you own workflows.

You select a profile template through the Profiles > Create Profile… dropdown:

Once you select a profile template, you can review the settings and extensions, and remove individual items if you don’t want to include them in your new Profile. After creating the new profile based on the template, changes made to settings, extensions, or UI are persisted in your profile.

Getting Started with Python in Visual Studio Code | Python with VSCode
Getting Started with Python in Visual Studio Code | Python with VSCode

Why use VSCode for Python?

Virtual Studio Code (VSCode) is a perfect Integrated Development Environment for Python. It is simple and comes with built-in features that enhance the development experience. VSCode Python extensions come with powerful features like syntax autocomplete, linting, debugging, unit testing, GitOps, virtual environments, notebooks, editing tools, and the ability to customize the editor.

Key Features:

  1. Command Palette to access all commands by typing keywords.
  2. Fully customizable keyboard shortcuts.
  3. Jupyter extension for data science. Run Jupyter notebook within the IDE.
  4. Auto linting and formatting.
  5. Debugging and Testing.
  6. Git integration.
  7. Custom code snippets.
  8. Enhanced editing tools. Multi cursor selection, column selection, outline view, side-by-side preview, and search and modify.

In this tutorial, we will start by installing Python and VSCode, then run a Python script in VSCode. After that, we will customize the editor to enhance the Python development experience by installing essential extensions and learning about built-in features. In the end, we will learn about Python productivity hacks.

Install and use packages

Let’s build upon the previous example by using packages.

In Python, packages are how you obtain any number of useful code libraries, typically from PyPI, that provide additional functionality to your program. For this example, you use the

numpy

package to generate a random number.

Return to the Explorer view (the top-most icon on the left side, which shows files), open

hello.py

, and paste in the following source code:


import numpy as np msg = "Roll a dice" print(msg) print(np.random.randint(1,9))

Tip: If you enter the above code by hand, you may find that auto-completions change the names after the


as

keywords when you press Enter at the end of a line. To avoid this, type a space, then Enter.

Next, run the file in the debugger using the “Python: Current file” configuration as described in the last section.

You should see the message, “ModuleNotFoundError: No module named ‘numpy'”. This message indicates that the required package isn’t available in your interpreter. If you’re using an Anaconda distribution or have previously installed the

numpy

package you may not see this message.

To install the

numpy

package, stop the debugger and use the Command Palette to run Terminal: Create New Terminal (⌃⇧` (Windows, Linux Ctrl+Shift+`)). This command opens a command prompt for your selected interpreter.

To install the required packages in your virtual environment, enter the following commands as appropriate for your operating system:

  1. Install the packages


    # Don't use with Anaconda distributions because they include matplotlib already. # macOS python3 -m pip install numpy # Windows (may require elevation) py -m pip install numpy # Linux (Debian) apt-get install python3-tk python3 -m pip install numpy

  2. Now, rerun the program, with or without the debugger, to view the output!

Congrats on completing the Python tutorial! During the course of this tutorial, you learned how to create a Python project, create a virtual environment, run and debug your Python code, and install Python packages. Explore additional resources to learn how to get the most out of Python in Visual Studio Code!

How to Setup Python in Visual Studio Code on Windows 11
How to Setup Python in Visual Studio Code on Windows 11

Install a Python interpreter

Along with the Python extension, you need to install a Python interpreter. Which interpreter you use is dependent on your specific needs, but some guidance is provided below.

Windows

Install Python from python.org. Use the Download Python button that appears first on the page to download the latest version.

Note: If you don’t have admin access, an additional option for installing Python on Windows is to use the Microsoft Store. The Microsoft Store provides installs of supported Python versions.

For additional information about using Python on Windows, see Using Python on Windows at Python.org

macOS

The system install of Python on macOS is not supported. Instead, a package management system like Homebrew is recommended. To install Python using Homebrew on macOS use

brew install python3

at the Terminal prompt.

Note: On macOS, make sure the location of your VS Code installation is included in your PATH environment variable. See these setup instructions for more information.

Linux

The built-in Python 3 installation on Linux works well, but to install other Python packages you must install

pip

with get-pip.py.

Other options

  • Data Science: If your primary purpose for using Python is Data Science, then you might consider a download from Anaconda. Anaconda provides not just a Python interpreter, but many useful libraries and tools for data science.

  • Windows Subsystem for Linux: If you are working on Windows and want a Linux environment for working with Python, the Windows Subsystem for Linux (WSL) is an option for you. If you choose this option, you’ll also want to install the WSL extension. For more information about using WSL with VS Code, see VS Code Remote Development or try the Working in WSL tutorial, which will walk you through setting up WSL, installing Python, and creating a Hello World application running in WSL.

Note: To verify that you’ve installed Python successfully on your machine, run one of the following commands (depending on your operating system):

Linux/macOS: open a Terminal Window and type the following command:


python3 --version

Windows: open a command prompt and run the following command:


py -3 --version

If the installation was successful, the output window should show the version of Python that you installed. Alternatively, you can use the


py -0

command in the VS Code integrated terminal to view the versions of python installed on your machine. The default interpreter is identified by an asterisk (*).

What are IDEs and Code Editors?

IDEs and code editors are tools that software developers use to write and edit code.

  • IDEs, or Integrated Development Environments, are usually more feature-rich and include tools for debugging, building and deploying code.
  • Code editors are generally more straightforward and focused on code editing. Many developers use IDEs and code editors, depending on the task.
How to learn Python programming | Guido van Rossum and Lex Fridman
How to learn Python programming | Guido van Rossum and Lex Fridman

Why Choose Python?

The programmers love to work with Python because of the increased productivity. As there is no compilation step, the edit-test-debug cycle is faster. Most importantly, Debugging Python programs is an easy task. A lousy input or a bug will never cause a segmentation fault. Instead, the interpreter discovers an error, raises an exception, and the interpreter prints a stack trace.

The source-level debugger allows for inspecting the local and global variables, setting breakpoints, evaluating arbitrary expressions, and much more.

The debugger is written in Python only, testifying to Python’s introspective power.

Furthermore, the fastest method to debug a program is to add a few print statements to the source code. The fastest edit test debug cycle makes it simple and more effective.

How to Get Python?

Here are the following steps to install Python on your PC.

  • Select the version of Python to download the full installer and install.
  • Download Python Executable Installer and install it.
  • Please wait for it to complete the installation process.
  • Verification of installation of Python in windows.
  • Run Python
  • Verify the Pip has been installed.

Environments

The Python extension automatically detects Python interpreters that are installed in standard locations. It also detects conda environments as well as virtual environments in the workspace folder. See Configuring Python environments.

The current environment is shown on the right side of the VS Code Status Bar:

The Status Bar also indicates if no interpreter is selected:

The selected environment is used for IntelliSense, auto-completions, linting, formatting, and any other language-related feature. It is also activated when you run or debug Python in a terminal, or when you create a new terminal with the Terminal: Create New Terminal command.

To change the current interpreter, which includes switching to conda or virtual environments, select the interpreter name on the Status Bar or use the Python: Select Interpreter command.

VS Code prompts you with a list of detected environments as well as any you’ve added manually to your user settings (see Configuring Python environments).

3 PYTHON AUTOMATION PROJECTS FOR BEGINNERS
3 PYTHON AUTOMATION PROJECTS FOR BEGINNERS

Create a virtual environment

A best practice among Python developers is to use a project-specific

virtual environment

. Once you activate that environment, any packages you then install are isolated from other environments, including the global interpreter environment, reducing many complications that can arise from conflicting package versions. You can create non-global environments in VS Code using Venv or Anaconda with Python: Create Environment.

Open the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)), start typing the Python: Create Environment command to search, and then select the command.

The command presents a list of environment types, Venv or Conda. For this example, select Venv.

The command then presents a list of interpreters that can be used for your project. Select the interpreter you installed at the beginning of the tutorial.

After selecting the interpreter, a notification will show the progress of the environment creation and the environment folder (

/.venv

) will appear in your workspace.

Ensure your new environment is selected by using the Python: Select Interpreter command from the Command Palette.

Note: For additional information about virtual environments, or if you run into an error in the environment creation process, see Environments.

Test your install

Quickly check your installation of Python support:

  1. Launch Visual Studio.

  2. Select Alt + I to open the Python Interactive window.

  3. In the window, enter the statement


    2+2

    .

    The statement output

    displays in the window. If you don’t see the correct output, recheck your steps.

Goodbye VS Code
Goodbye VS Code

Debugging and Testing in VSCode

Debugging

The Python extension comes with Debugging for all kinds of applications like multi-threaded, web, and remote applications. We can set breakpoints, inspect data, and run programs step by step.

Select a debug configuration

Launch the debug tab by clicking on the debug icon on the action bar or by using the keyboard shortcut Ctrl + Shift +D. To customize Debug options, click on create a launch.json file and select Python File.

Debug Panel

Run the Debug by clicking on the blue button Run and Debug, and it will run the Python file and show us the Variables, Watch, Call Stack, and breakpoints.

Quick debug

For quick debugging, you can always click on the down arrow beside the Run button and select Debug Python File.

Testing

The Python extension supports unittest and pytest testing frameworks. Instead of reading the test results in a terminal, you can review and resolve the issues within the Testing tab in an active bar.

Configure Python tests

After clicking on the Testing button, we will click on the Configure Python Tests button and select the testing framework. Usually, VSCode automatically detects the framework and displays all the tests in a tree view.

Learn about Python unit testing, implementing Python’s pytest testing framework by following our how to use pytest for unit testing tutorial.

Note: The testing example that we are using is from Visual Studio Code official documentation.

Run the unittest

We can run the Unit test by clicking on the Run Test button in the Testing tab and analyzing the results.

As we can observe, 1 of 2 tests have passed, and it has displayed the reasoning behind the failed result. VSCode testing is highly interactive and user-friendly.

What are the Basics of Python?

Let us understand the basics of Python. After understanding the basic terminologies, you can create a simple python program.

Fundamentals:

  • Syntax: It is the basic Python programming syntax
  • Variables: It explains how to create concise and meaningful variables.
  • Strings: You learn about string data and some bais string operations.
  • Booleans: The Boolean data type, falsy and truthy values in Python.
  • Constants: It shows you how to define constants in Python.
  • Comments: You can learn how to make notes in your code.
  • Type conversion: You will learn how to convert a value of one type to another. I.e., converting a string to a number.

Operators:

  • Comparison operators: You will understand the operators and how to use them to compare two variables.
  • Logical operators: Show you how to imbibe the logical operators to combine multiple conditions.

Control Flow:

  • If.else statement: learn to execute a code block based on a condition.
  • Ternary operator: You will understand the Python ternary operator that makes your code more concise.
  • Break: You will learn how to exit a loop prematurely.
  • Pass: It shows you how to use the pass statement as a placeholder.

Functions:

  • Python functions: You will know the function in Python and how to define and reuse functions in the program.
  • Keyword arguments: how to use the keyword arguments to make the function call more obvious.
  • Recursive functions: You will learn how to define recursive functions in Python.
  • Docstrings: show how you can use the docstrings to document a function.

List:

  • Tuple: you must know the tuple, a list that doesn’t change throughout the program.
  • Sort a list in place: Use the sort method to sort a list in place.
  • Unpack a list: Using the list unpacking method, it guides you on allot list elements to multiple variables.
  • List comprehensions: It shows you how to create a new list based on an old list.
  • Filter list elements with filter: You can use the filter function to filter the list of elements.
  • Iterables: You must understand the Difference between an iterable and an iterator.

Dictionaries:

  • Dictionary introduces you to the dictionary type.
  • Dictionary comprehension tells you how to use dictionary comprehension to create a new dictionary from an existing one.

Sets:

  • Sets: it explains the set type and shows you how to manipulate set elements effectively.
  • Union Sets: Using the union method, it shows you how to union two or more sets.
  • The intersection of sets shows you how to intersect two or more sets using the intersection method or set intersection operator.
  • Symmetric Difference of sets: It guides you in identifying the symmetric Difference of sets using the symmetric difference method.
  • Subset: it checks if a set is a subset of another set.

Exception Handling:

  • Try except: it shows you how to handle exceptions gracefully using the try-except statement.
  • Try-except-else: it explains how to use the try-except else statement to manage the follow of the program if in case of exceptions.

More on Python Loop:

  • For else: you must understand the for else statement.
  • While else: you need to understand the whole else statement.

More on Python functions:

  • Unpacking tuples: it shows you how to unpack a tuple that allows the individual elements of a tuple to be multiple variables.
  • Partial functions: You will learn how to define partial functions.
  • Type hints: It shows you how to add type hints to the parameters of functions.
How To Create & Activate A Virtual Environment In Visual Studio Code (Python 3.12)
How To Create & Activate A Virtual Environment In Visual Studio Code (Python 3.12)

Choose The Right Software Development Program

This table compares various courses offered by Simplilearn, based on several key features and details. The table provides an overview of the courses’ duration, skills you will learn, additional benefits, among other important factors, to help learners make an informed decision about which course best suits their needs.

Program Name Automation Testing Masters Program Full Stack Developer – MEAN Stack Caltech Coding Bootcamp Geo All All US University Simplilearn Simplilearn Caltech Course Duration 11 Months 11 Months 6 Months Coding Experience Required Basic Knowledge Basic Knowledge Basic Knowledge Skills You Will Learn Java, AWS, API Testing, TDD, etc. HTML, CSS, Express.js, API Testing, etc. Java, JavaScript, Angular, MongoDB, etc. Additional Benefits Structured Guidance

Learn From ExpertsHands-on Training

Blended Learning Program

Learn 20+ Tools and SkillsIndustry Aligned Projects

Caltech Campus Connect

Career Services17 CEU Credits

Cost $$ $$ $$$$ Explore Program Explore Program Explore Program

IDECode Editor: What’s the Difference?

  • An Integrated Development Environment (IDE) is a software application that provides tools and resources to help developers write and debug code. An IDE typically includes

    • A source code editor
    • A compiler or interpreter
    • An integrated debugger
    • A graphical user interface (GUI)
  • A code editor is a text editor program designed specifically for editing source code. It typically includes features that help in code development, such as syntax highlighting, code completion, and debugging.
  • The main difference between an IDE and a code editor is that an IDE has a graphical user interface (GUI) while a code editor does not. An IDE also has features such as code completion, syntax highlighting, and debugging, which are not found in a code editor.
  • Code editors are generally simpler than IDEs, as they do not include many other IDE components. As such, code editors are typically used by experienced developers who prefer to configure their development environment manually.
You MUST WATCH THIS before installing PYTHON. PLEASE DON'T MAKE this MISTAKE.
You MUST WATCH THIS before installing PYTHON. PLEASE DON’T MAKE this MISTAKE.

Create a Python source code file

From the File Explorer toolbar, select the New File button on the

hello

folder:

Name the file

hello.py

, and VS Code will automatically open it in the editor:

By using the

.py

file extension, you tell VS Code to interpret this file as a Python program, so that it evaluates the contents with the Python extension and the selected interpreter.

Note: The File Explorer toolbar also allows you to create folders within your workspace to better organize your code. You can use the New folder button to quickly create a folder.

Now that you have a code file in your Workspace, enter the following source code in

hello.py

:


msg = "Roll a dice" print(msg)

When you start typing

IntelliSense and auto-completions work for standard Python modules as well as other packages you’ve installed into the environment of the selected Python interpreter. It also provides completions for methods available on object types. For example, because the

msg

variable contains a string, IntelliSense provides string methods when you type

msg.

:

Finally, save the file (⌘S (Windows, Linux Ctrl+S)). At this point, you’re ready to run your first Python file in VS Code.

For full details on editing, formatting, and refactoring, see Editing code. The Python extension also has full support for Linting.

Which IDE to Use When?

We will divide the preference into three categories:

Based on Your Level of Knowledge

  • Beginner: IDLE, Thonny would be the perfect choice for first-time programmers who are just getting into Python.
  • Intermediate: For intermediate-level users, PyCharm, VS Code, Atom, and Sublime Text 3 are good options.

Based on Your End Goal

  • Data Science: Spyder, Jupyter Notebook, PyCharm professional (Paid).
  • Web Development: VS Code, PyCharm professional (Paid).
  • Scripting: Atom, PyDev, Sublime Text 3, PyCharm Community (Free).

Based on the Hardware You Use

  • Basic (Pentium, Celeron): IDLE, Atom, Sublime Text 3, Online IDEs.
  • Developer (Intel core series): PyCharm, Jupyter, Spyder, VS Code, Eclipse + PyDev.
THIS Is My CLEAN Setup For Coding In Python (2023)
THIS Is My CLEAN Setup For Coding In Python (2023)

Install a Python interpreter

Along with the Python extension, you need to install a Python interpreter. Which interpreter you use is dependent on your specific needs, but some guidance is provided below.

Windows

Install Python from python.org. Use the Download Python button that appears first on the page to download the latest version.

Note: If you don’t have admin access, an additional option for installing Python on Windows is to use the Microsoft Store. The Microsoft Store provides installs of supported Python versions.

For additional information about using Python on Windows, see Using Python on Windows at Python.org

macOS

The system install of Python on macOS is not supported. Instead, a package management system like Homebrew is recommended. To install Python using Homebrew on macOS use

brew install python3

at the Terminal prompt.

Note: On macOS, make sure the location of your VS Code installation is included in your PATH environment variable. See these setup instructions for more information.

Linux

The built-in Python 3 installation on Linux works well, but to install other Python packages you must install

pip

with get-pip.py.

Other options

  • Data Science: If your primary purpose for using Python is Data Science, then you might consider a download from Anaconda. Anaconda provides not just a Python interpreter, but many useful libraries and tools for data science.

  • Windows Subsystem for Linux: If you are working on Windows and want a Linux environment for working with Python, the Windows Subsystem for Linux (WSL) is an option for you. If you choose this option, you’ll also want to install the WSL extension. For more information about using WSL with VS Code, see VS Code Remote Development or try the Working in WSL tutorial, which will walk you through setting up WSL, installing Python, and creating a Hello World application running in WSL.

Note: To verify that you’ve installed Python successfully on your machine, run one of the following commands (depending on your operating system):

Linux/macOS: open a Terminal Window and type the following command:


python3 --version

Windows: open a command prompt and run the following command:


py -3 --version

If the installation was successful, the output window should show the version of Python that you installed. Alternatively, you can use the


py -0

command in the VS Code integrated terminal to view the versions of python installed on your machine. The default interpreter is identified by an asterisk (*).

Open source

Fork us on Github

Python Tools for Visual Studio is a completely free extension, developed and supported by Microsoft with contributions from the community. Visit our Github page to see or participate in PTVS development.

Python in Visual Studio Code

Working with Python in Visual Studio Code, using the Microsoft Python extension, is simple, fun, and productive. The extension makes VS Code an excellent Python editor, and works on any operating system with a variety of Python interpreters. It leverages all of VS Code’s power to provide auto complete and IntelliSense, linting, debugging, and unit testing, along with the ability to easily switch between Python environments, including virtual and conda environments.

This article provides only an overview of the different capabilities of the Python extension for VS Code. For a walkthrough of editing, running, and debugging code, use the button below.

How to install Python 3.12.0 on Windows 11
How to install Python 3.12.0 on Windows 11

Requirements for a Good Python Coding Environment

So what do you really need in a coding environment? Feature lists vary from app to app, but there are some core features that make coding easier:

  • Save and reload code files: If an IDE or editor won’t let you save your work and reopen everything later, in the same state it was in when you left, then it’s not much of an IDE.
  • Run code from within the environment: Similarly, if you have to drop out of the editor to run your Python code, then it’s not much more than a simple text editor.
  • Debugging support: Being able to step through your code as it runs is a core feature of all IDEs and most good code editors.
  • Syntax highlighting: Being able to quickly spot keywords, variables, and symbols in your code makes reading and understanding code much easier.
  • Automatic code formatting: Any editor or IDE worth its salt will recognize the colon at the end of a

    while

    or

    for

    statement and know the next line should be indented.

Of course, there are lots of other features that you might want, like source code control, an extension model, build and test tools, language help, and so on. But the above list gives you an idea of the core features that a good editing environment should support.

With these features in mind, take a look at some general-purpose tools that you can use for Python development.

What is Python Programming?

Python programming is an object-oriented, high-level programming language with dynamic semantics. Python combines high-level built-in data structures and dynamic typing and binding, making it very attractive for application development. In addition, Python is used as a scripting language to connect the existing components, it is easier to learn the syntax, and hence it reduces the cost of program maintenance.

Python encourages program modularity and code reuse. In addition, the interpreter and the extensive standard library are available in binary form or source and can be freely distributed.

Top 7 Best Extensions In VSCode For Python Programming That I Use For Data Science Projects
Top 7 Best Extensions In VSCode For Python Programming That I Use For Data Science Projects

Run Python code

Click the Run Python File in Terminal play button in the top-right side of the editor.

The button opens a terminal panel in which your Python interpreter is automatically activated, then runs

python3 hello.py

(macOS/Linux) or

python hello.py

(Windows):

There are three other ways you can run Python code within VS Code:

  1. Right-click anywhere in the editor window and select Run > Python File in Terminal (which saves the file automatically):

  2. Select one or more lines, then press Shift+Enter or right-click and select Run Selection/Line in Python Terminal. This command is convenient for testing just a part of a file.

  3. From the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)), select the Python: Start REPL command to open a REPL terminal for the currently selected Python interpreter. In the REPL, you can then enter and run lines of code one at a time.

Congrats, you just ran your first Python code in Visual Studio Code!

Key Takeaways

So, which code editor is right for you? Only you can decide that, but in this tutorial, you’ve gotten a taste of your options. Before you continue your quest for the perfect development environment, why not check your understanding of what you’ve learned in this tutorial?

Below, you’ll find some questions that you can use to recap and solidify what you’ve just learned. After each question, you’ll find a brief explanation hidden in a collapsible section. Click the Show/Hide toggle to reveal the answer. Time to dive in!

An integrated development environment (IDE) is a software application that provides a comprehensive set of features. IDEs integrate several tools specifically designed for software development, including a code editor and tools for building, executing, and debugging programs. It usually includes version control, as well.

On the other hand, a dedicated code editor doesn’t have as many features, but it’ll typically provide syntax highlighting and code formatting. While code editors might not come with as many features, they can often work with debuggers and source control systems. The plus is that they’re typically smaller and faster than IDEs.

A good Python coding environment should be able to save and reload code files, run code from within the environment, provide debugging support, and offer syntax highlighting. Additionally, it should have automatic code formatting capabilities in line with Python’s syntax. These core features make coding easier and more efficient by providing an integrated environment for development.

Several general editors and IDEs support Python development. These include Visual Studio Code, Eclipse with PyDev, Sublime Text, GNU Emacs, Vi/Vim, and Visual Studio with PTVS.

Each of these tools has its own advantages and disadvantages. For instance, Eclipse with PyDev is an open-source IDE that’s very accessible for experienced Eclipse developers, but it can be overwhelming for beginners. Sublime Text is a popular code editor with a great community following, but it’s not free and lacks direct support for executing or debugging code.

For more on all of these general editors and IDEs, check out the associated sections of this tutorial.

Python-specific editors and IDEs are built exclusively for Python development. PyCharm, Spyder, and Thonny are among the most popular ones.

PyCharm is a full-featured IDE that supports Python development directly, with support for source control and projects. Spyder is an open-source Python IDE optimized for data science workflows, integrating well with Python data science libraries. Thonny is designed specifically for beginners and has a built-in version of Python, so it doesn’t require any extra downloads.

Your choice of a Python IDE or code editor largely depends on your needs and experience level. If you’re a beginner, then you might want to start with something that’s ready to go right out of the box and requires few customizations, as this will be easier to navigate and use. If you’re already using text editors for other tasks or developing other software, then you may find it easier to add Python capabilities to your existing tool kit.

Maybe you need more advanced features and could benefit from the extensive features of a full-fledged IDE like PyCharm or the flexibility of a code editor like Sublime Text or VS Code. Ultimately, your specific needs, preferences, and comfort level should guide your choice.

Join Now: Click here to join the Real Python Newsletter and you’ll never miss another Python tutorial, course update, or post.

So, what will you pick? Share your thoughts in the comments!

Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: Finding the Perfect Python Code Editor

Getting Started with Python in VS Code

In this tutorial, you will learn how to use Python 3 in Visual Studio Code to create, run, and debug a Python “Roll a dice” application, work with virtual environments, use packages, and more! By using the Python extension, you turn VS Code into a great, lightweight Python editor.

If you are new to programming, check out the Visual Studio Code for Education – Introduction to Python course. This course offers a comprehensive introduction to Python, featuring structured modules in a ready-to-code browser-based development environment.

To gain a deeper understanding of the Python language, you can explore any of the programming tutorials listed on python.org within the context of VS Code.

For a Data Science focused tutorial with Python, check out our Data Science section.

Automating My Life with Python: The Ultimate Guide | Code With Me
Automating My Life with Python: The Ultimate Guide | Code With Me

Install and use packages

Let’s build upon the previous example by using packages.

In Python, packages are how you obtain any number of useful code libraries, typically from PyPI, that provide additional functionality to your program. For this example, you use the

numpy

package to generate a random number.

Return to the Explorer view (the top-most icon on the left side, which shows files), open

hello.py

, and paste in the following source code:


import numpy as np msg = "Roll a dice" print(msg) print(np.random.randint(1,9))

Tip: If you enter the above code by hand, you may find that auto-completions change the names after the


as

keywords when you press Enter at the end of a line. To avoid this, type a space, then Enter.

Next, run the file in the debugger using the “Python: Current file” configuration as described in the last section.

You should see the message, “ModuleNotFoundError: No module named ‘numpy'”. This message indicates that the required package isn’t available in your interpreter. If you’re using an Anaconda distribution or have previously installed the

numpy

package you may not see this message.

To install the

numpy

package, stop the debugger and use the Command Palette to run Terminal: Create New Terminal (⌃⇧` (Windows, Linux Ctrl+Shift+`)). This command opens a command prompt for your selected interpreter.

To install the required packages in your virtual environment, enter the following commands as appropriate for your operating system:

  1. Install the packages


    # Don't use with Anaconda distributions because they include matplotlib already. # macOS python3 -m pip install numpy # Windows (may require elevation) py -m pip install numpy # Linux (Debian) apt-get install python3-tk python3 -m pip install numpy

  2. Now, rerun the program, with or without the debugger, to view the output!

Congrats on completing the Python tutorial! During the course of this tutorial, you learned how to create a Python project, create a virtual environment, run and debug your Python code, and install Python packages. Explore additional resources to learn how to get the most out of Python in Visual Studio Code!

Create a Python source code file

From the File Explorer toolbar, select the New File button on the

hello

folder:

Name the file

hello.py

, and VS Code will automatically open it in the editor:

By using the

.py

file extension, you tell VS Code to interpret this file as a Python program, so that it evaluates the contents with the Python extension and the selected interpreter.

Note: The File Explorer toolbar also allows you to create folders within your workspace to better organize your code. You can use the New folder button to quickly create a folder.

Now that you have a code file in your Workspace, enter the following source code in

hello.py

:


msg = "Roll a dice" print(msg)

When you start typing

IntelliSense and auto-completions work for standard Python modules as well as other packages you’ve installed into the environment of the selected Python interpreter. It also provides completions for methods available on object types. For example, because the

msg

variable contains a string, IntelliSense provides string methods when you type

msg.

:

Finally, save the file (⌘S (Windows, Linux Ctrl+S)). At this point, you’re ready to run your first Python file in VS Code.

For full details on editing, formatting, and refactoring, see Editing code. The Python extension also has full support for Linting.

How To Setup A Virtual Environment For Python In Visual Studio Code In 2023
How To Setup A Virtual Environment For Python In Visual Studio Code In 2023

Start VS Code in a workspace folder

By starting VS Code in a folder, that folder becomes your “workspace”.

Using a command prompt or terminal, create an empty folder called “hello”, navigate into it, and open VS Code (

code

) in that folder () by entering the following commands:


mkdir hello cd hello code .

Note: If you’re using an Anaconda distribution, be sure to use an Anaconda command prompt.

Alternately, you can create a folder through the operating system UI, then use VS Code’s File > Open Folder to open the project folder.

Run Python code

Click the Run Python File in Terminal play button in the top-right side of the editor.

The button opens a terminal panel in which your Python interpreter is automatically activated, then runs

python3 hello.py

(macOS/Linux) or

python hello.py

(Windows):

There are three other ways you can run Python code within VS Code:

  1. Right-click anywhere in the editor window and select Run > Python File in Terminal (which saves the file automatically):

  2. Select one or more lines, then press Shift+Enter or right-click and select Run Selection/Line in Python Terminal. This command is convenient for testing just a part of a file.

  3. From the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)), select the Python: Start REPL command to open a REPL terminal for the currently selected Python interpreter. In the REPL, you can then enter and run lines of code one at a time.

Congrats, you just ran your first Python code in Visual Studio Code!

Python 2-dars. Kerakli dasturlar
Python 2-dars. Kerakli dasturlar

What are the Different Ways of Coding in Python?

  • The Shell: Python is an interpreter language. It executes the code line by line. Python provides a Python Shell, which executes a single python command and displays the result. To run the Python Shell, open the command prompt on windows and the terminal window on mac. Write Python and press enter. Python prompt consists of three greater than symbols.
  • IDLE: After installation of Python comes with an integrated development and Learning Environment, which you will see shortened to IDLE or even IDE. These are a class of applications that help you write code more efficiently. While there are many IDEs for you to choose from, Python IDLE is bare-bones, making it the perfect tool for beginners.
  • Code Editor: it is as easy as a text editor with syntax highlighting and even code formatting capabilities. The code editors can execute code and control a debugger.

[Related reading: Why Learn Python? Reasons and Benefits of Learning Python]

Features of an IDE

Let’s look at some main features of an IDE:

Syntax Highlighting

An IDE that knows your language’s syntax can provide visual cues and keywords that are easier to read by visually clarifying the language syntax.

Code without Syntax

Code with Syntax

Autocomplete

IDEs are generally really good at anticipating what you’re more likely to type next, making coding significantly faster and simpler.

Building Executables

IDE takes care of interpreting the Python code, running python scripts, building executables, and debugging the applications.

Debugging

In the event that a program does not run correctly, programmers can easily detect their code eros using the debugging tools that IDEs offer.

How to run Python in Visual Studio Code on Windows 10/11 [ 2024 Update ] Python Developers
How to run Python in Visual Studio Code on Windows 10/11 [ 2024 Update ] Python Developers

Full-featured debugging

One of Visual Studio’s strengths is its powerful debugger. For Python in particular, Visual Studio includes Python/C++ mixed-mode debugging, remote debugging on Linux, debugging within the Interactive window, and debugging Python unit tests.

In Visual Studio 2019 and later, you can run and debug code without having a Visual Studio project file. See Quickstart: Open and run Python code in a folder for an example.

For more information:

  • Debug Python
  • Python/C++ mixed-mode debugging
  • Remote debugging on Linux
  • Feature tour of the Visual Studio Debugger

Version Control integration

Collaborate on code with Git

Use Git as the default source control experience in Visual Studio right out of the box. From the new Git menu, you can create or clone repositories from GitHub or Azure DevOps. Use the integrated Git tool windows to commit and push changes to your code, manage branches, sync with your remote repositories, and resolve merge conflicts.

How to run Python in Visual Studio Code
How to run Python in Visual Studio Code

What is the Possible Answer?

Now that you have seen the Best Python IDEs that are currently available and their features, you can always decide which IDE to pick based on your requirements.

If you are looking for the most effective way to this tech industry of web development, a great way to start would be to enroll in the comprehensive Post Graduate Program in Full Stack Web Development. With this course, you will gain all the practical and work-ready skills you’d need to be employable and grab the best opportunities for you in the field.

Do you have any more queries regarding which Python IDE is best for you? Simply shoot us your question in the comments section. And our experts will get back to you as soon as possible!

Visual Studio Code Python for Data Science

Visual Studio Code allows users to simply run the data science code in Jupyter Notebook. We can run the cell and visualize the result within VSCode. It supports all kinds of programming languages and comes with built-in features to mimic the browser-based Jupyter notebook that we all love.

Learn more about Jupyter Notebooks by reading our How to use Jupyter Notebook tutorial.

To use the Jupyter notebook extension, we need to first install a Jupyter notebook.


pip install jupyterlab

Or


pip install notebook

Note: Jupyter Notebook and Jupyter Lab come with Anaconda Distribution, so we don’t have to install anything.

Install Jupyter Extension

After that, install the Jupyter extension from the Visual Studio marketplace.

To create a Jupyter notebook file, we can either create a new file with .ipynb extension or access the command palette (Ctrl+Shift+P) and select Jupyter: Create New Jupyter Notebook.

Pick the Ipython Kernel

To initialize the Jupyter server, we need to select the kernel by clicking on the kernel picker in the top right of the notebook, as shown in the image.

Note: By default, Anaconda comes with Python version 3.9.13. You can download the latest version of Python 3.11, but it won’t support all packages.

Run the Jupyter cell

Write a print expression to display “Hello World” and press the run button.

Add another cell

You can use the B key or click on + Code to add a new cell and run the cell with Ctrl + ⤶ Enter. You can learn about Jupyter keyboard shortcuts on defkey.

For R language users, we have got a Notebooks for R tutorial. You will learn to use R in a Jupyter Notebook and useful features.

Note: if you are looking for a hassle-free way of using Jupyter Notebook, then try DataCamp Workspace. It comes with essential Python libraries, a pre-build environment, and it supports various database integration.

The 5 Best Python IDE's and Editors
The 5 Best Python IDE’s and Editors

Free Python and Data Science lessons

NASA-inspired lessons

This learning path enables students to use Python to explore doing analyses and projects inspired from real-world problems faced by National Aeronautics and Space Administration (NASA) scientists. View full details of the lessons under NASA-inspired Lessons.

Learn Python with Over The Moon

These space-themed lessons were inspired by the Netflix film, Over the Moon, and will introduce students to data science, machine learning, and artificial intelligence using Python and Azure. View full details on Learn Python with Over The Moon.

Wonder Woman-inspired lessons

Give an introduction to Python with “Wonder Woman 1984”-inspired lessons that help students learn about the basics like conditionals and variables. Get full lesson details under Learn Python with Wonder Woman.

Python in Notebooks

Learn the basics of Python. View the full lesson at Write basic Python in Notebooks in Visual Studio Code.

Set up your Python beginner development environment

A step-by-step guide to installing and setting up your Python and VS Code environment. View the full lesson at Set up your Python beginner development environment with Visual Studio Code.

Introduction to IDEs and Code Editors

An integrated development environment (IDE) is a program dedicated to software development. As the name implies, IDEs integrate several tools specifically designed for software development. These tools usually include:

  • An editor designed to handle code (with, for example, syntax highlighting and auto-completion)
  • Build, execution, and debugging tools
  • Some form of source control

Most IDEs support many different programming languages and contain many more features. They can, therefore, be large and take time to download and install. You may also need advanced knowledge to use them properly.

In contrast, a dedicated code editor can be as simple as a text editor with syntax highlighting and code formatting capabilities. Most good code editors can execute code and control a debugger. The very best ones interact with source control systems as well. Compared to an IDE, a good dedicated code editor is usually smaller and quicker, but often less feature rich.

Visual Studio Code (Windows) - Setting up a Python Development Environment and Complete Overview
Visual Studio Code (Windows) – Setting up a Python Development Environment and Complete Overview

Configure and run the debugger

Let’s now try debugging our Python program. Debugging support is provided by the Python Debugger extension, which is automatically installed with the Python extension. To ensure it has been installed correctly, open the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)) and search for

@installed python debugger

. You should see the Python Debugger extension listed in the results.

Next, set a breakpoint on line 2 of

hello.py

by placing the cursor on the

Next, to initialize the debugger, press F5. Since this is your first time debugging this file, a configuration menu will open from the Command Palette allowing you to select the type of debug configuration you would like for the opened file.

Note: VS Code uses JSON files for all of its various configurations;


launch.json

is the standard name for a file containing debugging configurations.

Select Python File, which is the configuration that runs the current file shown in the editor using the currently selected Python interpreter.

The debugger will start, and then stop at the first line of the file breakpoint. The current line is indicated with a yellow arrow in the left margin. If you examine the Local variables window at this point, you can see that the

msg

variable appears in the Local pane.

A debug toolbar appears along the top with the following commands from left to right: continue (F5), step over (F10), step into (F11), step out (⇧F11 (Windows, Linux Shift+F11)), restart (⇧⌘F5 (Windows, Linux Ctrl+Shift+F5)), and stop (⇧F5 (Windows, Linux Shift+F5)).

The Status Bar also changes color (orange in many themes) to indicate that you’re in debug mode. The Python Debug Console also appears automatically in the lower right panel to show the commands being run, along with the program output.

To continue running the program, select the continue command on the debug toolbar (F5). The debugger runs the program to the end.

Tip Debugging information can also be seen by hovering over code, such as variables. In the case of


msg

, hovering over the variable will display the string

Roll a dice!

in a box above the variable.

You can also work with variables in the Debug Console (If you don’t see it, select Debug Console in the lower right area of VS Code, or select it from the … menu.) Then try entering the following lines, one by one, at the > prompt at the bottom of the console:


msg msg.capitalize() msg.split()

Select the blue Continue button on the toolbar again (or press F5) to run the program to completion. “Roll a dice!” appears in the Python Debug Console if you switch back to it, and VS Code exits debugging mode once the program is complete.

If you restart the debugger, the debugger again stops on the first breakpoint.

To stop running a program before it’s complete, use the red square stop button on the debug toolbar (⇧F5 (Windows, Linux Shift+F5)), or use the Run > Stop debugging menu command.

For full details, see Debugging configurations, which includes notes on how to use a specific Python interpreter for debugging.

Tip: Use Logpoints instead of print statements: Developers often litter source code with

Top Python IDEs

Now that you know about the integrated Development Environment, let’s look at a few popular Python IDEs. Note that we won’t be ranking these IDEs just for the sake of it because we believe that different IDEs are meant for various purposes.

But, we will indeed discuss which IDE you should use according to your needs or requirements. This will help remove any doubts that you may have and help you make a choice that best suits your purpose.

IDLE

  • IDLE (Integrated Development and Learning Environment) is a default editor that accompanies Python
  • This IDE is suitable for beginner-level developers
  • The IDLE tool can be used on Mac OS, Windows, and Linux
  • Price: Free
The most notable features of IDLE include:
  • Ability to search for multiple files
  • Interactive interpreter with syntax highlighting, and error and i/o messages
  • Smart indenting, along with basic text editor features
  • A very capable debugger
  • Its a great Python IDE for Windows

Image Source: Stack overflow

PyCharm

  • PyCharm is a widely used Python IDE created by JetBrains
  • This IDE is suitable for professional developers and facilitates the development of large Python projects
  • Price: Freemium
The most notable features of PyCharm include:
  • Support for JavaScript, CSS, and TypeScript
  • Smart code navigation
  • Quick and safe code refactoring
  • Support features like accessing databases directly from the IDE
  • Its a great Python IDE for Windows

Visual Studio Code

  • Visual Studio Code is an open-source (and free) IDE created by Microsoft. It finds great use in Python development
  • VS Code is lightweight and comes with powerful features that only some of the paid IDEs offer
  • Price: Free
The most notable features of Visual Studio Code include:
  • One of the best smart code completion is based on various factors
  • Git integration
  • Code debugging within the editor
  • It provides an extension to add additional features like code linting, themes, and other services

Sublime Text 3

  • Sublime Text is a very popular code editor. It supports many languages, including Python
  • It is highly customizable and also offers fast development speeds and reliability
  • Price: Free
The most notable features of Sublime Text 3 include:
  • Syntax highlighting
  • Custom user commands for using the IDE
  • Efficient project directory management
  • It supports additional packages for the web and scientific Python development
  • Its a great Python IDE for Windows

Atom

  • Atom is an open-source code editor by GitHub and supports Python development
  • Atom is similar to Sublime Text and provides almost the same features emphasis on speed and usability
  • Price: Free
The most notable features of Atom include:
  • Support for a large number of plugins
  • Smart autocompletion
  • Supports custom commands for the user to interact with the editor
  • Support for cross-platform development

Jupyter

  • Jupyter is widely used in the field of data science
  • It is easy to use, interactive and allows live code sharing and visualization
  • Price: Free
The most notable features of Jupyter include:
  • Supports for the numerical calculations and machine learning workflow
  • Combine code, text, and images for greater user experience
  • Intergeneration of data science libraries like NumPy, Pandas, and Matplotlib

Spyder

  • Spyder is an open-source IDE most commonly used for scientific development
  • Spyder comes with Anaconda distribution, which is popular for data science and machine learning
  • Price: Free
The most notable features of Spyder include:
  • Support for automatic code completion and splitting
  • Supports plotting different types of charts and data manipulation
  • Integration of data science libraries like NumPy, Pandas, and Matplotlib
  • Its a great Python IDE for Windows

PyDev

  • PyDev is a strong python interpreter and is distributed as a third-party plugin for Eclipse IDE
  • Being flexible, it is one of the preferred open-source IDE by the developers
  • Price: Free
The most notable features of PyDev include:
  • Django integration, auto code completion, and code coverage
  • Supports type hinting, refactoring, as well as debugging and code analysis
  • Good support for Python web development

Thonny

  • Thonny is an IDE ideal for teaching and learning Python programming
  • Price: Free
The most notable features of Thonny include:
  • Simple debugger
  • Function evaluation
  • Automatic syntax error detection
  • Detailed view of variables used in a Python program or project

Wing

  • The wing is also a popular IDE that provides a lot of good features to ensure a productive environment
  • Wing offers a 30-day trial version for the developers to check and understand the features of this IDE
  • Price: US $95 – US$179 for commercial license
The most notable features of Wing include:
  • It provides immediate feedback to your Python code
  • It provides support for test-driven development with unit tests, Pytest, and Django testing framework.
  • It assists in remote development
  • Auto code completion is present

Vim:

It is a flexible, open-source terminal-based text editor. Vi Improved, which means it is a revamped version of the Vi text editor.

GNU/Emacs:

finding the right code editor for python development can be tricky. Emacs is a set of macro extensions for different code editors. Richard Stallman adopted it into the GNU project in the early 1980s.

Dreamweaver:

it is one of the popular web development IDE tools. It helps you to create, publish and manage websites. It can be uploaded to any web server.

Eric:

It is a full-featured python editor and IDE, built on the cross-platform Qt GUI development framework. It has excellent plug-in management support.

Visual Studio:

It is an integrated development environment from Microsoft. It is used to develop computer programs such as web services, web apps, and mobile applications.

Pyscripter:

It has all the features expected in a modern Python IDE in a lightweight package. It is also natively compiled for windows to combine minimal memory consumption with maximum performance.

Rodeo:

It is one of the best IDEs for Python. It was developed for data science-related tasks like taking data and information from different resources and also plotting for issues. It supports cross-platform functionality. It can also be used as an IDE for experimenting interactively.

Python and Visual Studio Code Installation
Python and Visual Studio Code Installation

Python-Specific Editors and IDEs

PyCharm

Category: IDEWebsite: https://www.jetbrains.com/pycharm/

One of the best (and only) full-featured, dedicated IDEs for Python is PyCharm. Available in both paid (Professional) and free open-source (Community) editions, PyCharm installs quickly and easily on Windows, macOS, and Linux platforms.

Out of the box, PyCharm supports Python development directly. You can just open a new file and start writing code. You can run and debug Python directly inside PyCharm, and it has support for source control and projects.

Pros: It’s the de facto Python IDE environment, with tons of support and a supportive community. It edits, runs, and debugs Python out of the box.

Cons: PyCharm can be slow to load, and the default settings may need tweaking for existing projects.

You can learn more about using this environment in PyCharm for Productive Python Development.

Spyder

Category: IDEWebsite: https://www.spyder-ide.org/

Spyder is an open-source Python IDE that’s optimized for data science workflows. Spyder comes included with the Anaconda package manager distribution, so depending on your setup, you may already have it installed on your machine.

What’s interesting about Spyder is that its target audience is data scientists using Python. You’ll notice this throughout. For example, Spyder integrates well with common Python data science libraries like SciPy, NumPy, and Matplotlib.

Spyder features most of the common IDE features that you might expect, such as a code editor with robust syntax highlighting, Python code completion, and even an integrated documentation browser.

A special feature that you probably won’t see in other Python editing environments is Spyder’s variable explorer, which allows you to display data using a table-based layout right inside your IDE. You might not have a need for this, but it’s still pretty neat. If you regularly do data science work using Python, then you might fall in love with this unique feature. The IPython/Jupyter integration is nice as well.

Overall, Spyder might feel more basic than other IDEs. You might want to view it more as a special-purpose tool rather than something that you’d use as your primary editing environment every day. What’s nice about this Python IDE is that it’s available for free on Windows, macOS, and Linux, and it’s a fully open-source software.

Pros: You’re a data scientist using the Anaconda Python distribution.

Cons: More experienced Python developers might find Spyder too basic to work with on a daily basis and instead opt for a more complete IDE or customized editor solution.

Thonny

Category: IDEWebsite: http://thonny.org/

A more recent addition to the Python IDE family, Thonny is billed as an IDE for beginners. Written and maintained by the Institute of Computer Science at the University of Tartu in Estonia, Thonny is available for all major platforms, with installation instructions on the site.

By default, Thonny installs with its own bundled version of Python, so you don’t need to install anything else new. More experienced users may need to tweak this setting so that Thonny will find and use libraries that are already installed.

Pros: You’re a beginning Python user and want an IDE that’s ready to roll.

Cons: More experienced Python developers will find Thonny too basic for most uses, and the built-in interpreter is something to work around, not with.

If you’re interested in using Thonny as your Python editor, be sure to read Real Python’s dedicated tutorial on Thonny, which goes into more depth and shows you additional features.

FAQs

Python IDEs are a great way to get started with coding in Python. However, there are a few things to keep in mind when choosing an IDE. Here are some frequently asked questions about Python IDEs:

What is the best Python IDE?

There is no one “best” Python IDE. However, a few IDEs are popular among Python developers, such as PyCharm, Atom, and Visual Studio Code.

What are the different IDEs of Python?

Python is a programming language with many different IDEs available. Some popular IDEs include PyCharm, Atom, and Visual Studio Code. Each IDE has its unique features and benefits.

  • PyCharm, for example, is a popular IDE for Python development that offers code completion, error checking, and support for various Python frameworks.
  • Atom is a popular open-source IDE that is highly customizable and offers multiple plugins.
  • Visual Studio Code is a popular IDE for Python development that offers IntelliSense, which provides code completion and error checking.

What are the features of a good Python IDE?

A good Python IDE should have code completion, syntax highlighting, and code navigation features. It should also be easy to install and use.

What are the benefits of using a Python IDE?

Using a Python IDE can help you write code more efficiently and accurately and help you find and fix errors in your code.

Python support in Visual Studio on Windows

Python is a popular programming language that’s reliable, flexible, easy to learn, free to use on all operating systems, and supported by both a strong developer community and many free libraries. Python supports all manner of development, including web applications, web services, desktop apps, scripting, and scientific computing. Scientists, casual developers, professional developers, and many universities alike use Python for programming. You can learn more about the language on python.org and Python for Beginners.

Visual Studio is a powerful Python IDE on Windows. Visual Studio provides open-source support for the Python language through the Python Development and Data Science workloads (Visual Studio 2017 and later) and the free Python Tools for Visual Studio extension (Visual Studio 2015 and earlier). Tour the Visual Studio IDE to familiarize yourself with the IDE features for writing and editing Python code.

Visual Studio Code is available on Mac and Linux. For more information, see questions and answers.

To get started:

  • Follow the installation instructions to set up the Python workload.

  • Familiarize yourself with the Python capabilities of Visual Studio through the sections in this article.

  • Go through one or more of the Quickstarts to create a project. If you’re unsure, start with Quickstart: Open and run Python code in a folder or Create a web app with Flask.

  • Follow the Work with Python in Visual Studio tutorial for a full end-to-end experience.

VS Code vs Pycharm: Which IDE is the Best for Python Programming?
VS Code vs Pycharm: Which IDE is the Best for Python Programming?

Key Takeaways

So, which code editor is right for you? Only you can decide that, but in this tutorial, you’ve gotten a taste of your options. Before you continue your quest for the perfect development environment, why not check your understanding of what you’ve learned in this tutorial?

Below, you’ll find some questions that you can use to recap and solidify what you’ve just learned. After each question, you’ll find a brief explanation hidden in a collapsible section. Click the Show/Hide toggle to reveal the answer. Time to dive in!

An integrated development environment (IDE) is a software application that provides a comprehensive set of features. IDEs integrate several tools specifically designed for software development, including a code editor and tools for building, executing, and debugging programs. It usually includes version control, as well.

On the other hand, a dedicated code editor doesn’t have as many features, but it’ll typically provide syntax highlighting and code formatting. While code editors might not come with as many features, they can often work with debuggers and source control systems. The plus is that they’re typically smaller and faster than IDEs.

A good Python coding environment should be able to save and reload code files, run code from within the environment, provide debugging support, and offer syntax highlighting. Additionally, it should have automatic code formatting capabilities in line with Python’s syntax. These core features make coding easier and more efficient by providing an integrated environment for development.

Several general editors and IDEs support Python development. These include Visual Studio Code, Eclipse with PyDev, Sublime Text, GNU Emacs, Vi/Vim, and Visual Studio with PTVS.

Each of these tools has its own advantages and disadvantages. For instance, Eclipse with PyDev is an open-source IDE that’s very accessible for experienced Eclipse developers, but it can be overwhelming for beginners. Sublime Text is a popular code editor with a great community following, but it’s not free and lacks direct support for executing or debugging code.

For more on all of these general editors and IDEs, check out the associated sections of this tutorial.

Python-specific editors and IDEs are built exclusively for Python development. PyCharm, Spyder, and Thonny are among the most popular ones.

PyCharm is a full-featured IDE that supports Python development directly, with support for source control and projects. Spyder is an open-source Python IDE optimized for data science workflows, integrating well with Python data science libraries. Thonny is designed specifically for beginners and has a built-in version of Python, so it doesn’t require any extra downloads.

Your choice of a Python IDE or code editor largely depends on your needs and experience level. If you’re a beginner, then you might want to start with something that’s ready to go right out of the box and requires few customizations, as this will be easier to navigate and use. If you’re already using text editors for other tasks or developing other software, then you may find it easier to add Python capabilities to your existing tool kit.

Maybe you need more advanced features and could benefit from the extensive features of a full-fledged IDE like PyCharm or the flexibility of a code editor like Sublime Text or VS Code. Ultimately, your specific needs, preferences, and comfort level should guide your choice.

Join Now: Click here to join the Real Python Newsletter and you’ll never miss another Python tutorial, course update, or post.

So, what will you pick? Share your thoughts in the comments!

Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: Finding the Perfect Python Code Editor

Other popular Python extensions

The Microsoft Python extension provides all of the features described previously in this article. Additional Python language support can be added to VS Code by installing other popular Python extensions.

  1. Open the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)).
  2. Filter the extension list by typing ‘python’.

The extensions shown above are dynamically queried. Click on an extension tile above to read the description and reviews to decide which extension is best for you. See more in the Marketplace.

Best Python IDE: Vim, Emacs, PyCharm, or Visual Studio Code? | Guido van Rossum and Lex Fridman
Best Python IDE: Vim, Emacs, PyCharm, or Visual Studio Code? | Guido van Rossum and Lex Fridman

Python and Visual Studio Code Setup

In this part, we will learn to install Python and VSCode and run a simple Python code.

Installing Python

Downloading and installing the latest version of Python is straightforward. Go to Python.org and download the latest version for Windows. The installer is also available for Linux/Unix, macOS, and other platforms. After downloading the installer, install Python with default settings.

Image from Python.org

The most popular way of installing Python is through Anaconda Distribution. It comes with a pre-installed package and software for us to start coding without hiccups. It is available for Windows, macOS, and Linux operating systems.

Image from Anaconda

After installing Python on our operating system, check whether it is properly working by typing the following command in CLI / Terminal.


python --version

Output:


Python 3.9.13

Other Python installation methods

We can also install Python using various CLI tools or through the Windows store.

You can check out our full guide on how to install Python for more details. Similarly, our interactive Introduction to Python course helps you master the basics of Python syntax, lists, functions, packages, and Numpy.

Installing VSCode

Installing VSCode is super simple. Download and install the stable build from the official website. The installer is available for all kinds of operating systems, including web browsers.

Image from Visual Studio Code

Other VSCode installation methods

We can install using Microsoft store, Snap Store, and multiple CLI tools for Windows, Linux, and macOS.

Running Python in VSCode

After installing Python and VSCode, it is time to write a simple code and run the Python file within the IDE.

Create a new file

At start, you will see the welcome note. Ignore that and go to File > New Text File or use the keyboard shortcut Ctrl + N to create a new file. After that, write a simple print expression to display “Hello World.”

Save Python file

Save the file using Ctrl + S. Select the file directory and type the file name. Make sure to add `.py` at the end of the file name.

Select the interpreter

To run the Python file, we need to select the Python interpreter. By default, the Anaconda environment comes with Python version 3.9.13.

Run a Python file

To run the Python file, simply click on the Run button on the top left, as shown in the image. It will initialize the terminal and run the Python file to display the output.

You can also type python test.py in the terminal to run the file present in the current directory.

Start VS Code in a workspace folder

By starting VS Code in a folder, that folder becomes your “workspace”.

Using a command prompt or terminal, create an empty folder called “hello”, navigate into it, and open VS Code (

code

) in that folder () by entering the following commands:


mkdir hello cd hello code .

Note: If you’re using an Anaconda distribution, be sure to use an Anaconda command prompt.

Alternately, you can create a folder through the operating system UI, then use VS Code’s File > Open Folder to open the project folder.

My Python Development Environment Setup - Full Tutorial
My Python Development Environment Setup – Full Tutorial

Project system, and project and item templates

Visual Studio helps you manage the complexity of a project as it grows over time. A Visual Studio project is more than a folder structure. A project aids in the understanding of how different files are used and how they relate to each other. Visual Studio helps you distinguish app code, test code, web pages, JavaScript, build scripts, and so on, which then enable file-appropriate features. A Visual Studio solution helps you manage multiple related projects, such as a Python project and a C++ extension project.

Note

In Visual Studio 2019 and later, you can open a folder containing Python code and run that code without creating a Visual Studio project or solution file. For more information, see Quickstart: Open and run Python code in a folder. Keep in mind that there are benefits to using a project file, as explained in this section.

The following image shows an example of a Visual Studio solution containing both Python and Flask projects in Solution Explorer.

Project and item templates automate the process of setting up different types of projects and files. The templates save you valuable time and relieve you from managing intricate and error-prone details. Visual Studio provides templates for web, Azure, data science, console, and other types of projects. You can find templates for files like Python classes, unit tests, Azure web configuration, HTML, and even Django apps.

For more information:

  • Manage Python projects
  • Item templates reference
  • Python project templates
  • Work with C++ and Python
  • Create project and item templates
  • Solutions and projects in Visual Studio

Tips and Tricks for Efficient Python Development in VSCode

VSCode comes with awesome Python development features and extensions. We can customize them to our needs and improve the productivity. In this section, we will learn about tips and tricks for efficient Python development.

  1. Getting started: Help > Get Started. Learn about VSCode’s customization and features by following guided tutorials.
  2. Command Palette: access entire all available commands by using the Keyboard shortcut: Ctrl+Shift+P. By writing keywords, we can access specific commands.
  3. Keyboard shortcuts: better than command palettes. We can modify keyboard shortcuts or memorize them by using keyboard reference sheets. It will help us access the commands directly, instead of searching with the keyword.
  4. Command line: launch the VSCode editor through the command line interface by typing `code .`. We can also customize how the editor is launched by adding additional arguments.
  5. Errors and warnings: quick jump to errors and warnings in a project by using the keyboard shortcut: Ctrl+Shift+M. We can also cycle through the error with F8 or Shift+F8.
  6. Customization: VSCode allows us to customize themes, keyboard shortcuts, JSON validation, debugging settings, fonts, and many more. It is a fully customizable IDE.
  7. Extensions: other Python extensions improve our development experience. Look for popular extensions on the Visual Studio Marketplace.
  8. Multi cursor selection: is a lifesaver. Add cursors at arbitrary positions by using Alt+Click. It will allow us to modify multiple lines of code at once. We can also use Ctrl+Shift+L to modify all occurrences of the current selection.
  9. Search and modify: this is the best tool for searching and modifying multiple expressions at once. We can also rename the symbol by selecting the symbol and typing F2.
  10. Git integration: allows us to perform all Git-related tasks within IDE. It provides an easy-to-use GUI for diff, views, staging, branching, committing, merging, and more.
  11. Code Snippets: is our best friend. Just like Autohotkey, we are creating templates for repeating code patterns. To create a custom code snippet, select File > Preferences > Configure User Snippets and then select the language.
  12. GitHub Copilot: is a winner extension for all kinds of development. It enhances the coding experience with artificial intelligence (AI) by suggesting lines of code or entire functions.

Bonus: sync your settings by logging into your GitHub account. It will sync your settings across all of the machines.

How to Run Python in Visual Studio Code on Windows 10 2022 Best IDE
How to Run Python in Visual Studio Code on Windows 10 2022 Best IDE

General Editors and IDEs with Python Support

Visual Studio Code

Category: Code EditorWebsite: https://code.visualstudio.com/Python tools: https://marketplace.visualstudio.com/items?itemName=ms-python.python

Visual Studio Code (also known as VS Code) is a full-featured code editor available for Linux, macOS, and Windows platforms. Small and lightweight, but full-featured, VS Code is open source, extensible, and configurable for almost any task. VS Code is built on Electron, a framework for creating desktop applications using JavaScript, HTML, and CSS.

Installing Python support in VS Code is very accessible: the Marketplace is a quick button click away. Search for Python, click Install, and restart if necessary. VS Code will recognize your Python installation and libraries automatically.

Pros: Thanks to Electron, VS Code is available on every platform, surprisingly full-featured despite having a small footprint, and open source.

Cons: Electron means VS Code isn’t a native app. Plus, some people may have principled reasons for not using Microsoft resources.

Be sure to consult the tutorial on using Visual Studio Code for Python development, as well as the follow-up tutorial going more in-depth, to make the most of this setup. If you’re working in Windows, then check out the Setting Up VS Code section in Your Python Coding Environment on Windows: Setup Guide.

Eclipse + PyDev

Category: IDEWebsite: www.eclipse.orgPython tools: PyDev, www.pydev.org

If you’ve spent any amount of time in the open-source community, then you’ve probably heard about Eclipse. Available for Linux, Windows, and macOS, Eclipse is the de facto open-source IDE for Java development. It has a rich marketplace of extensions and add-ons, which makes Eclipse useful for a wide range of development activities.

One such extension is PyDev, which enables Python debugging, code completion, and an interactive Python console. Installing PyDev into Eclipse is straightforward: from Eclipse, select Help then Eclipse Marketplace, and search for PyDev. Click Install and restart Eclipse if necessary.

Pros: If you’ve already got Eclipse installed, then adding PyDev will be quicker and easier. PyDev is very accessible for the experienced Eclipse developer.

Cons: If you’re just starting out with Python, or with software development in general, Eclipse can be a lot to handle. Remember how IDEs are larger and require more knowledge to use properly? Eclipse is all that and a bag of (micro)chips.

Sublime Text

Category: Code EditorWebsite: http://www.sublimetext.com

Written by a Google engineer with a dream for a better text editor, Sublime Text is an extremely popular code editor. Supported on all platforms, Sublime Text has built-in support for Python code editing and a rich set of extensions (called packages) that extend the syntax and editing features.

Installing additional Python packages can be tricky: all Sublime Text packages are written in Python itself, and installing community packages often requires you to execute Python scripts directly in Sublime Text.

Pros: Sublime Text has a great following in the community. As a code editor alone, Sublime Text is fast, small, and well supported.

Cons: Sublime Text isn’t free, although you can use the evaluation version for an indefinite period of time. Installing extensions can be tricky, and there’s no direct support for executing or debugging code from within the editor.

To make the most of your Sublime Text setup, read Real Python’s Python + Sublime Text setup guide and consider the in-depth video course that shows you how to craft an effective Python development setup with Sublime Text 3.

GNU Emacs

Category: Code EditorWebsite: https://www.gnu.org/software/emacs/

Back before the iPhone vs Android war, before the Linux vs Windows war, even before the PC vs Mac war, there was the Editor War, with GNU Emacs as one of the combatants. Billed as “the extensible, customizable, self-documenting, real-time display editor,” GNU Emacs has been around almost as long as UNIX and has a fervent following.

Always free and available on every platform (in one form or another), GNU Emacs uses a form of the powerful Lisp programming language for customization, and various customization scripts exist for Python development.

Pros: You know Emacs, you use Emacs, you love Emacs. Lisp is a second language, and you know the power it gives you means you can do anything.

Cons: Customization means writing (or copying and pasting) Lisp code into various script files. If a feature isn’t already provided, then you may have to learn Lisp to figure out how to do it.

Plus, you know that Emacs would be a great operating system, if only it had a good text editor…

Be sure to consult the Python + Emacs setup guide to make the most of this setup.

Vi / Vim

Category: Code EditorWebsite: https://www.vim.org/

On the other side of the Text Editor War stands Vi (also known as Vim). Included by default on almost every UNIX system and macOS, Vi has an equally fervent following.

Vi and Vim are modal editors, separating the viewing of a file from the editing of a file. Vim includes many improvements on the original Vi, including an extensibility model and in-place code building. Vim Scripts are available for various Python development tasks.

Pros: You know Vi, you use Vi, you love Vi. Vim Scripts don’t scare you, and you know you can bend Vi to your will.

Cons: Like with Emacs, you’re not comfortable finding or writing your own scripts to enable Python development, and you’re not sure how a modal editor is supposed to work.

Plus, you know that Vi would be a great text editor, if only it had a decent operating system.

If you’re going with this combination, check out the Python + VIM setup guide with tips and plugin recommendations.

Visual Studio

Category: IDEWebsite: https://www.visualstudio.com/vs/Python tools: Python Tools for Visual Studio, aka PTVS

Built by Microsoft and not to be confused with Visual Studio Code, Visual Studio is a full-featured IDE, in many ways comparable to Eclipse. Built for Windows and macOS only, VS comes in both free (Community) and paid (Professional and Enterprise) versions. Visual Studio enables development for a variety of platforms and comes with its own marketplace for extensions.

Python Tools for Visual Studio (PTVS) enables Python coding in Visual Studio, as well as Intellisense for Python, debugging, and other tools.

Pros: If you already have Visual Studio installed for other development activities, then adding PTVS is quicker and easier.

Cons: Visual Studio is a big download for just Python. Plus, if you’re on Linux, you’re out of luck: there’s no Visual Studio install for that platform.

Installing Essential VSCode Python Extensions

The VSCode’s Python extensions will provide us with the helping functionalities for code editing, docstrings, linting, formatting, debugging, testing, and environment selection.

How to install a VSCode Extension

Click on the box icon on the activity bar or use a keyboard shortcut: Ctrl + Shift + X to open the extension panel. Type any keyword in the search bar to explore all kinds of extensions.

Install VSCode Python extension

In our case, we will type Python and install the Python extension by clicking on the install button, as shown above.

List of Essential Python Extensions

Python

The Python extension automatically installs Pylance, Jupyter, and isort extensions. It comes with a complete collection of tools for Data Science, web development, and software engineering.

Key Features:

Python extension comes with IntelliSense, linting, debugging, code navigation, code formatting, refactoring, variable explorer, and test explorer.

  • IntelliSense (code autocomplete)
  • Linting (Pylint, Flake8)
  • Code formatting (black, autopep)
  • Debugging
  • Testing (unittest, pytest)
  • Jupyter Notebooks
  • Environments (venv, pipenv, conda)
  • Refactoring
Indent-rainbow

Indent-rainbow extensions provide us with a multilevel colorized indentation for improved code readability. We get alternating colors on each step, and it helps us avoid common indentation errors.

Python Indent

Python Indent extension helps us with creating indentations. By pressing the Enter key, the extension will parse the Python file and determine how the next line should be indented. It is a time saver.

Jupyter Notebook Renderers

Jupyter Notebook Renderers is part of the Jupyter extension pack. It helps us render plotly, vega, gif, png, svg, and jpeg output.

autoDocstring

The autoDocstring extension helps us quickly generate docstring for Python functions. By typing triple quotes “”” or ”’ within the function, we can generate and modify docstring. Learn more about doc strings by following our Python Docstrings tutorial.

Note: Most Python development extensions and features come with Python extensions.

How to Run Python 3.12 in Visual Studio Code on Windows 10 [2023]| Run Sample Python Program
How to Run Python 3.12 in Visual Studio Code on Windows 10 [2023]| Run Sample Python Program

Next steps

To learn how to build web apps with popular Python web frameworks, see the following tutorials:

There is then much more to explore with Python in Visual Studio Code:

  • Python profile template – Create a new profile with a curated set of extensions, settings, and snippets
  • Editing code – Learn about autocomplete, IntelliSense, formatting, and refactoring for Python.
  • Linting – Enable, configure, and apply a variety of Python linters.
  • Debugging – Learn to debug Python both locally and remotely.
  • Testing – Configure test environments and discover, run, and debug tests.
  • Settings reference – Explore the full range of Python-related settings in VS Code.
  • Deploy Python to Azure App Service
  • Deploy Python to Container Apps

Install Python support in Visual Studio

Python support is available only on Visual Studio for Windows. On Mac and Linux, Python support is available through Visual Studio Code.

Bifurcation Based on Experience Level and End Goal

There are two main types of IDEs for Python: those designed for experienced developers and those designed for beginners.

  • Experienced developers often prefer IDEs that offer more features and allow them to customize the development environment to their preferences.
  • On the other hand, beginners often prefer IDEs with fewer features that are easier to learn and use.
  • The most popular IDEs for experienced Python developers are PyCharm and Visual Studio Code. PyCharm is a full-featured IDE that offers many features, including code completion, code navigation, refactoring, and debugging. Visual Studio Code is a more lightweight IDE that is popular for its ease of use and extensibility.
  • The two most popular IDEs for beginner Python developers are IDLE and Pythonista. IDLE is a very simple IDE included with the Python standard library, and Pythonista is a more full-featured IDE that consists of a code editor, debugger, and interactive shell.
How to setup Python for VSCode in 3 mins only!! I Install Python and Setup VSCode for Windows 10!
How to setup Python for VSCode in 3 mins only!! I Install Python and Setup VSCode for Windows 10!

Run Python code

To experience Python, create a file (using the File Explorer) named

hello.py

and paste in the following code:


print("Hello World")

The Python extension then provides shortcuts to run Python code using the currently selected interpreter (Python: Select Interpreter in the Command Palette). To run the active Python file, click the Run Python File in Terminal play button in the top-right side of the editor.

You can also run individual lines or a selection of code with the Python: Run Selection/Line in Python Terminal command (Shift+Enter). If there isn’t a selection, the line with your cursor will be run in the Python Terminal. An identical Run Selection/Line in Python Terminal command is available on the context menu for a selection in the editor. The same terminal will be used every time you run a selection or a line in the terminal/REPL, until that terminal is closed. The same terminal is also used for Run Python File in Terminal. If that terminal is still running the REPL, you should exit the REPL (

exit()

) or switch to a different terminal before running a Python file.

The Python extension automatically removes indents based on the first non-empty line of the selection, shifting all other lines left as needed.

The command opens the Python Terminal if necessary; you can also open the interactive REPL environment directly using the Python: Start REPL command that activates a terminal with the currently selected interpreter and then runs the Python REPL.

For a more specific walkthrough and other ways of running code, see the run code tutorial.

Git Integration

VSCode comes with built-in Git integration. No more writing Git commands on terminals. Git integration provides a user-friendly GUI and helpful functions for diff, views, staging, branching, committing, merge, and more.

Check out our Git Cheat Sheet to learn about the various Git commands and functionalities.

Note: To enable Git integration, you need to install Git from official site.

Initializing Git

We can access it through the action bar or by using the keyboard shortcut: Ctrl + Shift + G. Before we start committing, we need to initialize the repository.

Git Commit

After that, add and commit the changes with the message. It is that simple.

Create a GitHub repository and push the code

You can even create a GitHub repository and push your code to a remote server by logging into your GitHub account.

Private GitHub repository

We have created a GitHub private repository of Python files and folders.

You can now simply commit and push the changes to the remote server without leaving the VSCode.

Follow our Github and Git tutorial to learn everything about Git and GitHub.

Debugging

No more

For more specific information on debugging in Python, such as configuring your

launch.json

settings and implementing remote debugging, see Debugging. General VS Code debugging information is found in the debugging document.

Additionally, the Django and Flask tutorials provide examples of how to implement debugging in the context of web applications, including debugging Django templates.

Testing

The Python extension supports testing with Python’s built-in unittest framework and pytest.

In order to run tests, you must enable one of the supported testing frameworks in the settings of your project. Each framework has its own specific settings, such as arguments for identifying the paths and patterns for test discovery.

Once the tests have been discovered, VS Code provides a variety of commands (on the Status Bar, the Command Palette, and elsewhere) to run and debug tests. These commands also allow you to run individual test files and methods

Conclusion

VSCode is not just a code editor. It is a complete ecosystem for efficient Python development. It provides us with shortcuts, Commands Palette, IntelliSense, linting, formatting, debugging, formatting, Git integrations, Jupyter notebook, third-party extensions, and a fully customizable development experience.

VSCode is highly recommended to beginners who are learning the basics of Python and data science. Complete Data Scientist with a Python career track to become a master in Python and data science. The career track consists of 25 courses and six projects to prepare you to become a professional data scientist.

A Deep Dive into the Phi-2 Model

Python List Size: 8 Different Methods for Finding the Length of a List in Python

An End-to-End ML Model Monitoring Workflow with NannyML in Python

Bex Tuychiev

15 min

Getting Started with Python in VS Code

In this tutorial, you will learn how to use Python 3 in Visual Studio Code to create, run, and debug a Python “Roll a dice” application, work with virtual environments, use packages, and more! By using the Python extension, you turn VS Code into a great, lightweight Python editor.

If you are new to programming, check out the Visual Studio Code for Education – Introduction to Python course. This course offers a comprehensive introduction to Python, featuring structured modules in a ready-to-code browser-based development environment.

To gain a deeper understanding of the Python language, you can explore any of the programming tutorials listed on python.org within the context of VS Code.

For a Data Science focused tutorial with Python, check out our Data Science section.

Python-Specific Editors and IDEs

PyCharm

Category: IDEWebsite: https://www.jetbrains.com/pycharm/

One of the best (and only) full-featured, dedicated IDEs for Python is PyCharm. Available in both paid (Professional) and free open-source (Community) editions, PyCharm installs quickly and easily on Windows, macOS, and Linux platforms.

Out of the box, PyCharm supports Python development directly. You can just open a new file and start writing code. You can run and debug Python directly inside PyCharm, and it has support for source control and projects.

Pros: It’s the de facto Python IDE environment, with tons of support and a supportive community. It edits, runs, and debugs Python out of the box.

Cons: PyCharm can be slow to load, and the default settings may need tweaking for existing projects.

You can learn more about using this environment in PyCharm for Productive Python Development.

Spyder

Category: IDEWebsite: https://www.spyder-ide.org/

Spyder is an open-source Python IDE that’s optimized for data science workflows. Spyder comes included with the Anaconda package manager distribution, so depending on your setup, you may already have it installed on your machine.

What’s interesting about Spyder is that its target audience is data scientists using Python. You’ll notice this throughout. For example, Spyder integrates well with common Python data science libraries like SciPy, NumPy, and Matplotlib.

Spyder features most of the common IDE features that you might expect, such as a code editor with robust syntax highlighting, Python code completion, and even an integrated documentation browser.

A special feature that you probably won’t see in other Python editing environments is Spyder’s variable explorer, which allows you to display data using a table-based layout right inside your IDE. You might not have a need for this, but it’s still pretty neat. If you regularly do data science work using Python, then you might fall in love with this unique feature. The IPython/Jupyter integration is nice as well.

Overall, Spyder might feel more basic than other IDEs. You might want to view it more as a special-purpose tool rather than something that you’d use as your primary editing environment every day. What’s nice about this Python IDE is that it’s available for free on Windows, macOS, and Linux, and it’s a fully open-source software.

Pros: You’re a data scientist using the Anaconda Python distribution.

Cons: More experienced Python developers might find Spyder too basic to work with on a daily basis and instead opt for a more complete IDE or customized editor solution.

Thonny

Category: IDEWebsite: http://thonny.org/

A more recent addition to the Python IDE family, Thonny is billed as an IDE for beginners. Written and maintained by the Institute of Computer Science at the University of Tartu in Estonia, Thonny is available for all major platforms, with installation instructions on the site.

By default, Thonny installs with its own bundled version of Python, so you don’t need to install anything else new. More experienced users may need to tweak this setting so that Thonny will find and use libraries that are already installed.

Pros: You’re a beginning Python user and want an IDE that’s ready to roll.

Cons: More experienced Python developers will find Thonny too basic for most uses, and the built-in interpreter is something to work around, not with.

If you’re interested in using Thonny as your Python editor, be sure to read Real Python’s dedicated tutorial on Thonny, which goes into more depth and shows you additional features.

Support for multiple interpreters

Visual Studio’s Python Environments window gives you a single place to manage all of your global Python environments, conda environments, and virtual environments. Visual Studio automatically detects installations of Python in standard locations, and allows you to configure custom installations. With each environment, you can easily manage packages, open an interactive window for that environment, and access environment folders.

Use the Open interactive window command to run Python interactively within the context of Visual Studio. Use the Open in PowerShell command to open a separate command window in the folder of the selected environment. In that command window, you can run any python script.

For more information:

Download and install the Python workload

Complete the following steps to download and install the Python workload.

  1. Download and run the latest Visual Studio Installer for Windows. Python support is present in release 15.2 and later. If you have Visual Studio installed already, open Visual Studio and run the installer by selecting Tools > Get Tools and Features.

    Tip

    The Community edition is for individual developers, classroom learning, academic research, and open source development. For other uses, install Visual Studio Professional or Visual Studio Enterprise.

  2. The installer provides a list of workloads that are groups of related options for specific development areas. For Python, select the Python development workload and select Install:

    Python installation options Description Python distributions Choose any combination of Python distribution that you plan to work with. Common options include 32-bit and 64-bit variants of Python 2, Python 3, Miniconda, Anaconda 2, and Anaconda 3. Each option includes the distribution’s interpreter, runtime, and libraries. Anaconda, specifically, is an open data science platform that includes a wide range of preinstalled packages. Visual Studio automatically detects existing Python installations. For more information, see The Python Environments window. Also, if a newer version of Python is available than the version shown in the installer, you can install the new version separately and Visual Studio detects it. Cookiecutter template support Install the Cookiecutter graphical UI to discover templates, input template options, and create projects and files. For more information, see Use the Cookiecutter extension. Python web support Install tools for web development including HTML, CSS, and JavaScript editing support, along with templates for projects using the Bottle, Flask, and Django frameworks. For more information, see Python web project templates. Python native development tools Install the C++ compiler and other necessary components to develop native extensions for Python. For more information, see Create a C++ extension for Python. Also install the Desktop development with C++ workload for full C++ support.

    By default, the Python workload installs for all users on a computer under:

    %ProgramFiles%\Microsoft Visual Studio\

    \

    Common7\IDE\Extensions\Microsoft\Python

    where

    is 2022 and

    is Community, Professional, or Enterprise.

    %ProgramFiles(x86)%\Microsoft Visual Studio\

    \

    Common7\IDE\Extensions\Microsoft\Python

    where

    is 2019 or 2017 and

    is Community, Professional, or Enterprise.

Next steps

To learn how to build web apps with popular Python web frameworks, see the following tutorials:

There is then much more to explore with Python in Visual Studio Code:

  • Python profile template – Create a new profile with a curated set of extensions, settings, and snippets
  • Editing code – Learn about autocomplete, IntelliSense, formatting, and refactoring for Python.
  • Linting – Enable, configure, and apply a variety of Python linters.
  • Debugging – Learn to debug Python both locally and remotely.
  • Testing – Configure test environments and discover, run, and debug tests.
  • Settings reference – Explore the full range of Python-related settings in VS Code.
  • Deploy Python to Azure App Service
  • Deploy Python to Container Apps

Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: Finding the Perfect Python Code Editor

Writing Python using IDLE or the Python shell is great for smaller tasks, but those tools quickly turn larger programming projects into frustrating pits of despair. Using an IDE, or even just a good dedicated code editor, makes coding fun—but which one is best for you?

Fear not, gentle reader! Here, you’ll demystify the myriad choices available to you. What works best for you will ultimately depend on you and your process, but you’ll get the pros and cons of each option so that you can make an informed decision.

To make things easier, you’ll break your list into two broad categories of tools: the ones built exclusively for Python development and the ones built for general development that you can use for Python. You’ll explore some Whys and Why Nots for each. Lastly, none of these options are mutually exclusive, so you can try them out on your own with very little penalty.

Join Now: Click here to join the Real Python Newsletter and you’ll never miss another Python tutorial, course update, or post.

But first, what are IDEs and code editors?

Requirements for a Good Python Coding Environment

So what do you really need in a coding environment? Feature lists vary from app to app, but there are some core features that make coding easier:

  • Save and reload code files: If an IDE or editor won’t let you save your work and reopen everything later, in the same state it was in when you left, then it’s not much of an IDE.
  • Run code from within the environment: Similarly, if you have to drop out of the editor to run your Python code, then it’s not much more than a simple text editor.
  • Debugging support: Being able to step through your code as it runs is a core feature of all IDEs and most good code editors.
  • Syntax highlighting: Being able to quickly spot keywords, variables, and symbols in your code makes reading and understanding code much easier.
  • Automatic code formatting: Any editor or IDE worth its salt will recognize the colon at the end of a

    while

    or

    for

    statement and know the next line should be indented.

Of course, there are lots of other features that you might want, like source code control, an extension model, build and test tools, language help, and so on. But the above list gives you an idea of the core features that a good editing environment should support.

With these features in mind, take a look at some general-purpose tools that you can use for Python development.

Online Compiler from Programiz

Programiz offers an online compiler that is simple to use and easy to access. The online compiler allows you to compile and run your code in seconds without downloading or installing any software. The online compiler can compile and run your code on Windows, Mac, Linux, and Android.

Vim

Vim is a highly configurable and special text editor used by programmers. It is a powerful tool that enhances editing files, performs search and replaces operations, and much more. Vim also supports syntax highlighting, which helps to make code more readable. Vim is especially popular among experienced coders and is often considered the most powerful text editor available.

GNU Emacs

GNU Emacs is a free and open-source text editor. Richard Stallman created it in 1985. Emacs is a powerful and extensible text editor. It has a rich set of features, including a built-in Lisp interpreter, powerful editing features, and support for a wide range of programming languages and file formats.

ActivePython

ActivePython is a distribution of Python created by ActiveState, which is available for Windows, Linux, and macOS X. ActivePython also includes many additional packages not found in the standard Python distribution. These include packages for scientific computing, data analysis, and web development. ActivePython is free to download and use for development purposes.

Python Extension Pack

Unsure which extensions to recommend to your students? You can point your students to the Python Education Extension Pack that contains essential and helpful extensions for the classroom. You can download the extension pack from the VS Code Marketplace:

The extension pack contains:

  • Python for basic Python functionality like compiling, debugging support, linting, Jupyter Notebooks, unit tests, and more.
  • Live Share to enable real-time collaboration.
  • Remote – SSH to work on remote projects (for example, to access lab machines) through SSH with full VS Code functionality.
  • Markdown+Math for full LaTeX support in Markdown.
  • Python Test Explorer for Visual Studio Code to visualize and run Python tests in the side bar.
  • Code Runner to run snippets (selected code) and single files of any code with a single click.

General Editors and IDEs with Python Support

Visual Studio Code

Category: Code EditorWebsite: https://code.visualstudio.com/Python tools: https://marketplace.visualstudio.com/items?itemName=ms-python.python

Visual Studio Code (also known as VS Code) is a full-featured code editor available for Linux, macOS, and Windows platforms. Small and lightweight, but full-featured, VS Code is open source, extensible, and configurable for almost any task. VS Code is built on Electron, a framework for creating desktop applications using JavaScript, HTML, and CSS.

Installing Python support in VS Code is very accessible: the Marketplace is a quick button click away. Search for Python, click Install, and restart if necessary. VS Code will recognize your Python installation and libraries automatically.

Pros: Thanks to Electron, VS Code is available on every platform, surprisingly full-featured despite having a small footprint, and open source.

Cons: Electron means VS Code isn’t a native app. Plus, some people may have principled reasons for not using Microsoft resources.

Be sure to consult the tutorial on using Visual Studio Code for Python development, as well as the follow-up tutorial going more in-depth, to make the most of this setup. If you’re working in Windows, then check out the Setting Up VS Code section in Your Python Coding Environment on Windows: Setup Guide.

Eclipse + PyDev

Category: IDEWebsite: www.eclipse.orgPython tools: PyDev, www.pydev.org

If you’ve spent any amount of time in the open-source community, then you’ve probably heard about Eclipse. Available for Linux, Windows, and macOS, Eclipse is the de facto open-source IDE for Java development. It has a rich marketplace of extensions and add-ons, which makes Eclipse useful for a wide range of development activities.

One such extension is PyDev, which enables Python debugging, code completion, and an interactive Python console. Installing PyDev into Eclipse is straightforward: from Eclipse, select Help then Eclipse Marketplace, and search for PyDev. Click Install and restart Eclipse if necessary.

Pros: If you’ve already got Eclipse installed, then adding PyDev will be quicker and easier. PyDev is very accessible for the experienced Eclipse developer.

Cons: If you’re just starting out with Python, or with software development in general, Eclipse can be a lot to handle. Remember how IDEs are larger and require more knowledge to use properly? Eclipse is all that and a bag of (micro)chips.

Sublime Text

Category: Code EditorWebsite: http://www.sublimetext.com

Written by a Google engineer with a dream for a better text editor, Sublime Text is an extremely popular code editor. Supported on all platforms, Sublime Text has built-in support for Python code editing and a rich set of extensions (called packages) that extend the syntax and editing features.

Installing additional Python packages can be tricky: all Sublime Text packages are written in Python itself, and installing community packages often requires you to execute Python scripts directly in Sublime Text.

Pros: Sublime Text has a great following in the community. As a code editor alone, Sublime Text is fast, small, and well supported.

Cons: Sublime Text isn’t free, although you can use the evaluation version for an indefinite period of time. Installing extensions can be tricky, and there’s no direct support for executing or debugging code from within the editor.

To make the most of your Sublime Text setup, read Real Python’s Python + Sublime Text setup guide and consider the in-depth video course that shows you how to craft an effective Python development setup with Sublime Text 3.

GNU Emacs

Category: Code EditorWebsite: https://www.gnu.org/software/emacs/

Back before the iPhone vs Android war, before the Linux vs Windows war, even before the PC vs Mac war, there was the Editor War, with GNU Emacs as one of the combatants. Billed as “the extensible, customizable, self-documenting, real-time display editor,” GNU Emacs has been around almost as long as UNIX and has a fervent following.

Always free and available on every platform (in one form or another), GNU Emacs uses a form of the powerful Lisp programming language for customization, and various customization scripts exist for Python development.

Pros: You know Emacs, you use Emacs, you love Emacs. Lisp is a second language, and you know the power it gives you means you can do anything.

Cons: Customization means writing (or copying and pasting) Lisp code into various script files. If a feature isn’t already provided, then you may have to learn Lisp to figure out how to do it.

Plus, you know that Emacs would be a great operating system, if only it had a good text editor…

Be sure to consult the Python + Emacs setup guide to make the most of this setup.

Vi / Vim

Category: Code EditorWebsite: https://www.vim.org/

On the other side of the Text Editor War stands Vi (also known as Vim). Included by default on almost every UNIX system and macOS, Vi has an equally fervent following.

Vi and Vim are modal editors, separating the viewing of a file from the editing of a file. Vim includes many improvements on the original Vi, including an extensibility model and in-place code building. Vim Scripts are available for various Python development tasks.

Pros: You know Vi, you use Vi, you love Vi. Vim Scripts don’t scare you, and you know you can bend Vi to your will.

Cons: Like with Emacs, you’re not comfortable finding or writing your own scripts to enable Python development, and you’re not sure how a modal editor is supposed to work.

Plus, you know that Vi would be a great text editor, if only it had a decent operating system.

If you’re going with this combination, check out the Python + VIM setup guide with tips and plugin recommendations.

Visual Studio

Category: IDEWebsite: https://www.visualstudio.com/vs/Python tools: Python Tools for Visual Studio, aka PTVS

Built by Microsoft and not to be confused with Visual Studio Code, Visual Studio is a full-featured IDE, in many ways comparable to Eclipse. Built for Windows and macOS only, VS comes in both free (Community) and paid (Professional and Enterprise) versions. Visual Studio enables development for a variety of platforms and comes with its own marketplace for extensions.

Python Tools for Visual Studio (PTVS) enables Python coding in Visual Studio, as well as Intellisense for Python, debugging, and other tools.

Pros: If you already have Visual Studio installed for other development activities, then adding PTVS is quicker and easier.

Cons: Visual Studio is a big download for just Python. Plus, if you’re on Linux, you’re out of luck: there’s no Visual Studio install for that platform.

Configure and run the debugger

Let’s now try debugging our Python program. Debugging support is provided by the Python Debugger extension, which is automatically installed with the Python extension. To ensure it has been installed correctly, open the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)) and search for

@installed python debugger

. You should see the Python Debugger extension listed in the results.

Next, set a breakpoint on line 2 of

hello.py

by placing the cursor on the

Next, to initialize the debugger, press F5. Since this is your first time debugging this file, a configuration menu will open from the Command Palette allowing you to select the type of debug configuration you would like for the opened file.

Note: VS Code uses JSON files for all of its various configurations;


launch.json

is the standard name for a file containing debugging configurations.

Select Python File, which is the configuration that runs the current file shown in the editor using the currently selected Python interpreter.

The debugger will start, and then stop at the first line of the file breakpoint. The current line is indicated with a yellow arrow in the left margin. If you examine the Local variables window at this point, you can see that the

msg

variable appears in the Local pane.

A debug toolbar appears along the top with the following commands from left to right: continue (F5), step over (F10), step into (F11), step out (⇧F11 (Windows, Linux Shift+F11)), restart (⇧⌘F5 (Windows, Linux Ctrl+Shift+F5)), and stop (⇧F5 (Windows, Linux Shift+F5)).

The Status Bar also changes color (orange in many themes) to indicate that you’re in debug mode. The Python Debug Console also appears automatically in the lower right panel to show the commands being run, along with the program output.

To continue running the program, select the continue command on the debug toolbar (F5). The debugger runs the program to the end.

Tip Debugging information can also be seen by hovering over code, such as variables. In the case of


msg

, hovering over the variable will display the string

Roll a dice!

in a box above the variable.

You can also work with variables in the Debug Console (If you don’t see it, select Debug Console in the lower right area of VS Code, or select it from the … menu.) Then try entering the following lines, one by one, at the > prompt at the bottom of the console:


msg msg.capitalize() msg.split()

Select the blue Continue button on the toolbar again (or press F5) to run the program to completion. “Roll a dice!” appears in the Python Debug Console if you switch back to it, and VS Code exits debugging mode once the program is complete.

If you restart the debugger, the debugger again stops on the first breakpoint.

To stop running a program before it’s complete, use the red square stop button on the debug toolbar (⇧F5 (Windows, Linux Shift+F5)), or use the Run > Stop debugging menu command.

For full details, see Debugging configurations, which includes notes on how to use a specific Python interpreter for debugging.

Tip: Use Logpoints instead of print statements: Developers often litter source code with

Essentials Python Learning Strategies

The essential Python fastest Learning strategies are given below:

  • You need to cover the fundamentals of Python.
  • Establish a goal for your study.
  • Select the best resources to learn Python, such as interactive and non-interactive websites and video resources.
  • Consider learning Python Library.
  • Speed up the Python installation: a process with Anaconda.
  • Select and Install an IDE
  • Use Google to troubleshoot the code.

Interactive window

For every Python environment known to Visual Studio, you can easily open the same interactive (REPL) environment for a Python interpreter directly within Visual Studio, rather than using a separate command prompt. You can easily switch between environments as well. To open a separate command prompt, select your desired environment in the Python Environments window, then select the Open in PowerShell command as explained earlier in the Support for multiple interpreters section.

Visual Studio also provides tight integration between the Python code editor and the Interactive window. The Ctrl+Enter keyboard shortcut conveniently sends the current line of code (or code block) in the editor to the Interactive window, then moves to the next line (or block). Ctrl+Enter lets you easily step through code without having to run the debugger. You can also send selected code to the Interactive window with the same keystroke, and easily paste code from the Interactive window into the editor. Together, these capabilities allow you to work out details for a segment of code in the Interactive window and easily save the results in a file in the editor.

Visual Studio also supports IPython/Jupyter in the REPL, including inline plots, .NET, and Windows Presentation Foundation (WPF).

For more information:

Requirements for a Good Python Coding Environment

There are a few critical requirements for a good Python coding environment:

  1. The environment should have a good code editor. A code editor is a unique text editor with special features for writing and editing code. Some common code editors for Python include Atom, Sublime Text, and Visual Studio Code.
  2. Python interpreters have an irreplaceable place in the python environment. The Python interpreter is a program that runs Python code. It can be used to run code interactively or to run code from a file.
  3. The environment should have a good set of libraries. Libraries are collections of code that can be used to extend the functionality of Python. Some shared libraries for Python include the standard library, NumPy, and SciPy.
  4. The environment should have a good set of debugging tools. Debugging tools are used to identify and fix errors in code.
  5. Python environment should have version control. Version control is an essential tool for managing changes to code. And popular version control systems include Git and Subversion (SVN).

Tools are programs that help with development tasks such as testing, debugging, and packaging. Some standard tools for Python include the Python debugger, the Python package manager, and the Python profiler.

Keywords searched by users: python ide visual studio

Python Development In Visual Studio Code – Real Python
Python Development In Visual Studio Code – Real Python
Visual Studio Python Ide - Python Development Tools For Windows
Visual Studio Python Ide – Python Development Tools For Windows
Visual Studio Python Ide - Python Development Tools For Windows
Visual Studio Python Ide – Python Development Tools For Windows
Python In Visual Studio Tutorial Step 1, Create A Project | Microsoft Learn
Python In Visual Studio Tutorial Step 1, Create A Project | Microsoft Learn
Visual Studio Python Ide - Python Development Tools For Windows
Visual Studio Python Ide – Python Development Tools For Windows
15+ Popular Python Ides In 2024: Choosing The Best One
15+ Popular Python Ides In 2024: Choosing The Best One
Python Support In Visual Studio On Windows | Microsoft Learn
Python Support In Visual Studio On Windows | Microsoft Learn
Getting Started With Python In Visual Studio Code | Python With Vscode -  Youtube
Getting Started With Python In Visual Studio Code | Python With Vscode – Youtube
Visual Studio: Ide And Code Editor For Software Developers And Teams
Visual Studio: Ide And Code Editor For Software Developers And Teams
Visual Studio 2019 Goes Live With C++, Python Shared Editing | Ars Technica
Visual Studio 2019 Goes Live With C++, Python Shared Editing | Ars Technica
15+ Popular Python Ides In 2024: Choosing The Best One
15+ Popular Python Ides In 2024: Choosing The Best One
Visual Studio 2022 (Python Getting Started) - Youtube
Visual Studio 2022 (Python Getting Started) – Youtube
Visual Studio Python Ide - Python Development Tools For Windows
Visual Studio Python Ide – Python Development Tools For Windows
Python Tools For Visual Studio: Leverage The Power Of The Visual Studio Ide  To Develop Better And More Efficient Python Projects: Sabia, Martino, Wang,  Cathy: 9781783288687: Amazon.Com: Books
Python Tools For Visual Studio: Leverage The Power Of The Visual Studio Ide To Develop Better And More Efficient Python Projects: Sabia, Martino, Wang, Cathy: 9781783288687: Amazon.Com: Books
Remote Python Development In Visual Studio Code - Python
Remote Python Development In Visual Studio Code – Python
Top 5 Open Source Python Ides | Opensource.Com
Top 5 Open Source Python Ides | Opensource.Com
11 Python Ides And Code Editors For Mac, Linux & Windows
11 Python Ides And Code Editors For Mac, Linux & Windows
What Is The Best Ide For Python? - Quora
What Is The Best Ide For Python? – Quora
Visual Studio Python Ide - Python Development Tools For Windows
Visual Studio Python Ide – Python Development Tools For Windows
Python In Visual Studio Tutorial Step 2, Write And Run Code | Microsoft  Learn
Python In Visual Studio Tutorial Step 2, Write And Run Code | Microsoft Learn
Setting Up Vscode For Python: A Complete Guide | Datacamp
Setting Up Vscode For Python: A Complete Guide | Datacamp
Edit Python Code And Use Intellisense - Visual Studio (Windows) | Microsoft  Learn
Edit Python Code And Use Intellisense – Visual Studio (Windows) | Microsoft Learn

See more here: kientrucannam.vn

Leave a Reply

Your email address will not be published. Required fields are marked *