Importing Python Libraries in VS Code (2024)

Recently, I have been diving into the world of python a bit more particularly webscraping, interaction with API etc. While I was looking to move from notebooks to code editors, a major problem I had was importing libraries. The solutions I found online were a little complex until I read a tutorial from the VS Code website and I thought to share that.
This write-up will be useful to you if you are trying to run python scripts in vscode or having issues importing python libraries. That been said, let get right into it!😀

Problem

Below is the error I encountered:

Importing Python Libraries in VS Code (2)

To follow along, you need to have vs code, python and python extension installed on your laptop.

Solution

First of all, when working on a project, you create a folder. This would help save all files associated with this project.
Open VS Code editor, navigate to folder destination and add folder.

Importing Python Libraries in VS Code (3)

Now that you have added your folder, create a virtual environment: A virtual environment helps isolate packages installation and reduce problems that may arise from conflicting package versions.
You do this by using the command palette(ctrl+shift+P), then type in and select ‘python:create environment’. A venv and conda will pop, then you select venv. You will be prompted to select a python interpreter after which the virtual environment will be created.

Importing Python Libraries in VS Code (4)

Next, you create your python file. A python file is created by adding a .py extension to the file name.

Importing Python Libraries in VS Code (5)

Next , I’m going to try to import the library so you can see the information it brings when I run the python file.

Importing Python Libraries in VS Code (6)

To import your library, create a new terminal by going to the command palette(ctrl+shift+p) and type ‘Python:create terminal’.

Importing Python Libraries in VS Code (7)

In your new terminal, type e.g “pip install pandas” or whatever library you want to install and press enter.

Importing Python Libraries in VS Code (8)

By the time we run our script again, it runs just fine.

Importing Python Libraries in VS Code (9)

And that’s done!! Now, you can go ahead and use the library.

Importing Python Libraries in VS Code (2024)
Top Articles
Does Your Shirt Hem Flip Up? There’s a Simple Way to Fix It
U.S. Tinder usage by gender 2020 | Statista
Funny Roblox Id Codes 2023
Www.mytotalrewards/Rtx
San Angelo, Texas: eine Oase für Kunstliebhaber
Golden Abyss - Chapter 5 - Lunar_Angel
Www.paystubportal.com/7-11 Login
Gore Videos Uncensored
Craigslist Greenville Craigslist
Top Hat Trailer Wiring Diagram
World History Kazwire
R/Altfeet
George The Animal Steele Gif
Nalley Tartar Sauce
Chile Crunch Original
Teenleaks Discord
Immortal Ink Waxahachie
Craigslist Free Stuff Santa Cruz
Mflwer
Costco Gas Foster City
Obsidian Guard's Cutlass
Mission Impossible 7 Showtimes Near Marcus Parkwood Cinema
Sprinkler Lv2
Uta Kinesiology Advising
Kcwi Tv Schedule
Nesb Routing Number
Olivia Maeday
Random Bibleizer
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Receptionist Position Near Me
Black Lion Backpack And Glider Voucher
Gopher Carts Pensacola Beach
Duke University Transcript Request
Nikki Catsouras: The Tragic Story Behind The Face And Body Images
Kiddie Jungle Parma
Lincoln Financial Field, section 110, row 4, home of Philadelphia Eagles, Temple Owls, page 1
The Latest: Trump addresses apparent assassination attempt on X
In Branch Chase Atm Near Me
Appleton Post Crescent Today's Obituaries
Craigslist Red Wing Mn
American Bully Xxl Black Panther
Ktbs Payroll Login
Jail View Sumter
Thotsbook Com
Funkin' on the Heights
Caesars Rewards Loyalty Program Review [Previously Total Rewards]
Marcel Boom X
Www Pig11 Net
Ty Glass Sentenced
Game Akin To Bingo Nyt
Ranking 134 college football teams after Week 1, from Georgia to Temple
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 5951

Rating: 4.7 / 5 (47 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.