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
Certification and Career Development Programs
Optimizing map content for performance—ArcMap
Joanna Gaines Coleslaw
Min Player Speed Threshold Madden 22
Yanina Molina Tv
Moana Nail Salon Katy Tx
Craigslist Farm And Garden Yakima Wa
Craigslist Cars For Sale Under 5000
Mountain Goat Dinar
Deborah Clearbranch
About iOS 18 Updates - Apple Support
Pennys Department Store Near Me
Pharmacies in Amsterdam (Apotheek) | Amsterdam.info
List of Amazon Fulfillment Center Locations [2024 Updated]
los angeles cars & trucks - by owner "used cars" - craigslist
Drago Funeral Home & Cremation Services - Astoria - New York - Funeral Homes | Tribute Archive
Jimmy John's Order Delivery
Stoughton Commuter Rail Schedule
Craigslist Akron Canton Ohio
Cookie Clicker Advanced Method Unblocked
Hca Scheduler Login
Peoplesoft Oracle Americold Login
Kays.candyworld
Bible Gateway passage: John 6 - New International Version
Xsammybearxox
Rubfinder
Zuercher Portal Inmates Clinton Iowa
Dashmart Bloomington
Hardage Giddens Chapel Hills Obituaries
Modesto Rainfall 2022
Standard Page Field
Mannat Indian Grocers
Bee & Willow™ 31-Piece LED Tea … curated on LTK
Chase Bank Operating Hours
Optum Primary Care - Winter Park Aloma
Master of Science in Data Science | Merrimack Online Programs
Chuckwalla relative / THU 4-4-24 / Gave a red card, informally / Derby participants in July / Game show host John Michael / Mission involving Spirit and Opportunity, in brief / What Scott Joplin might yell after a spill? / Kind of candle at a wedding cere
When His Eyes Opened Chapter 3096
Johnny's Bar & Grill Wesley Menu
B&B Auto Salvage Okc
Ewing Irrigation Prd
Gasprijs Nederland: per m3 in 2024 en de actuele gasprijzen
Syracuse Cars And Trucks Craigslist
Holly Holm Camel Toe
Samanthaschwartz Fapello
Td Bank Hours Weekend
Find your Routing Number (ABA) Transit Number - Wise
Two ways to avoid the DMV credit card surcharge: Roadshow
How Much Is Gas At Flying J
R/Clashroyale
Find The Markers Microwave Code
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.