Python in Visual Studio tutorial Step 5, install packages (2024)

  • Article

This article presents Step 5 in the tutorial series Work with Python in Visual Studio.

All code in a Python project runs within the context of a specific environment. Examples of environments include a global environment, a virtual environment, a conda environment, and so on. The environment is used for any tasks that require language services that are specific to the Python version and a set of installed packages. Each environment requires certain installed packages based on the project code.

The Python developer community produces thousands of useful packages that you can incorporate into your own projects. In Step 5 of this tutorial series, you use the Python Environments window in Visual Studio to manage packages in your Python environments.

In Step 5 of the tutorial, you learn how to:

  • View Python environments and packages in Visual Studio
  • Install and manage packages for Python environments
  • Test Python code with installed packages

Prerequisites

  • A Python application project that has a Python file (.py) with code created in Step 2: Write and run Python code.

View Python environments in Visual Studio

Visual Studio provides two places to view information about Python environments:

Use one of the following methods to open the Python Environments window:

  • To access the window from the main toolbar in Visual Studio, select View > Other Windows > Python Environments.

  • If you have a Python project open in Solution Explorer, right-click the Python Environments node under the project, and select View All Python Environments:

    You can also use the Ctrl+K, Ctrl+` keyboard shortcut to open the Python Environments window from Solution Explorer.

Prepare the Python file

To prepare for the exercise, follow these steps to update your Python project file to include the necessary code:

  1. Open your Python project file (.py) in the editor. (Tutorial Step 2 explains how to create this file, where the default file name is PythonApplication1.py.)

  2. Replace the code in the file with the following code. This version of the code creates a cosine wave similar to the output from tutorial Step 4, but it plots the output graphically.

    from math import radiansimport numpy as np # installed with matplotlibimport matplotlib.pyplot as pltdef main(): x = np.arange(0, radians(1800), radians(12)) plt.plot(x, np.cos(x), 'b') plt.show()main()
  3. In the editor, hover over the matplotlib import statement. Visual Studio uses special formatting to indicate the statement is unresolved.

    The matplotlib import statement is unresolved because the necessary packages aren't installed to the default global environment. You learn how to install the required packages in the next section.

Install packages for the Python environment

To resolve the matplotlib import statement, you need to install the necessary packages to the default global environment:

  1. In the Python Environments window, select the default environment for new Python projects, then select Packages (PyPI) in the dropdown menu. (PyPI is the acronym for the Python Package Index.)

    Visual Studio shows the list of packages currently installed in the default environment.

  2. In the Search field, enter matplotlib. In the results list, select the Run command: pip install matplotlib option.

    The command installs the matplotlib library, and also any packages it depends on. In this case, the dependent packages include the numpy library.

    You can open the View > Output window to monitor the progress of the installation.

  3. After the packages install, the Python Environments window refreshes to show the packages for the selected environment:

    The X to the right of the package uninstalls it.

Run the program

Now that the matplotlib library is installed, you're ready to test your program.

  1. Run your program with debugging (F5) or without the Debugger (Ctrl+F5).

  2. Check the program output. You should see a plot graph of the cosine data:

Next step

Step 6: Work with Git

Python in Visual Studio tutorial Step 5, install packages (2024)
Top Articles
These 14 Dermatologist-Owned Skincare Brands Will Majorly Upgrade Your Routine
3 Reasons to Buy Enbridge Stock Like There's No Tomorrow
Mybranch Becu
Www.mytotalrewards/Rtx
Why Are Fuel Leaks A Problem Aceable
NYT Mini Crossword today: puzzle answers for Tuesday, September 17 | Digital Trends
Enrique Espinosa Melendez Obituary
Fat People Falling Gif
Explore Tarot: Your Ultimate Tarot Cheat Sheet for Beginners
Poplar | Genus, Description, Major Species, & Facts
United Dual Complete Providers
fltimes.com | Finger Lakes Times
Everything You Need to Know About Holly by Stephen King
Flower Mound Clavicle Trauma
Lima Funeral Home Bristol Ri Obituaries
Curtains - Cheap Ready Made Curtains - Deconovo UK
What is Rumba and How to Dance the Rumba Basic — Duet Dance Studio Chicago | Ballroom Dance in Chicago
Simpsons Tapped Out Road To Riches
Brett Cooper Wikifeet
SF bay area cars & trucks "chevrolet 50" - craigslist
X-Chromosom: Aufbau und Funktion
SuperPay.Me Review 2023 | Legitimate and user-friendly
Baja Boats For Sale On Craigslist
Bill Remini Obituary
Sam's Club Gas Price Hilliard
2021 MTV Video Music Awards: See the Complete List of Nominees - E! Online
Receptionist Position Near Me
Best Town Hall 11
Login.castlebranch.com
My Dog Ate A 5Mg Flexeril
Sam's Club Near Wisconsin Dells
Newsday Brains Only
Tra.mypatients Folio
Linabelfiore Of
How Much Is Mink V3
Priscilla 2023 Showtimes Near Consolidated Theatres Ward With Titan Luxe
Body Surface Area (BSA) Calculator
About :: Town Of Saugerties
Topos De Bolos Engraçados
Join MileSplit to get access to the latest news, films, and events!
Gym Assistant Manager Salary
Kutty Movie Net
Quiktrip Maple And West
✨ Flysheet for Alpha Wall Tent, Guy Ropes, D-Ring, Metal Runner & Stakes Included for Hunting, Family Camping & Outdoor Activities (12'x14', PE) — 🛍️ The Retail Market
Sara Carter Fox News Photos
Paperlessemployee/Dollartree
Erica Mena Net Worth Forbes
Upcoming Live Online Auctions - Online Hunting Auctions
Laura Houston Wbap
Unpleasant Realities Nyt
Craigs List Sarasota
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 6533

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.