vs code how to install python package code example

Example 1: installing python packages in visual studio code

py -m pip install numpy

Example 2: how download library python vscode

"""
example: install matplotlib + numpy
open commandprompt(Win + R -> cmd)
"""
#fist of all make sure u have python installed
py -3 --version

#make the python project
#code:
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 20, 100)  # Create a list of evenly-spaced numbers over the range
plt.plot(x, np.sin(x))       # Plot the sine of each x point
plt.show()                   # Display the plot

#press F5
#You are going to get this error:"ModuleNotFoundError: No module named 'matplotlib'"
#this means matplotlib is not installed yet
#then press Ctrl + shift + ù  this will open a command prompt for the porject.
#type the following command and confirm you want to create a new virtual envirroment:

py -3 -m venv .venv
.venv\scripts\activate

#select the new envirroment by pressing (Ctrl + shifft + p)
#type "select interpreter" and select the ('.venv') interpreter
#the last step is to run the following command in the cmd
python -m pip install matplotlib

when running the script (F5) it should work now

Example 3: vs code install python package

py -3 -m venv .venv
.venv\scripts\activate

Tags:

Misc Example