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
China’s US Debt Sales Fuel Speculation
How to Factory Reset iPad without Apple ID Password [Easy]
Scheelzien, volwassenen - Alrijne Ziekenhuis
Worcester Weather Underground
417-990-0201
Coverage of the introduction of the Water (Special Measures) Bill
St Petersburg Craigslist Pets
Shorthand: The Write Way to Speed Up Communication
Wausau Marketplace
Green Bay Press Gazette Obituary
Whiskeytown Camera
Mndot Road Closures
The Wicked Lady | Rotten Tomatoes
Nj Scratch Off Remaining Prizes
DoorDash, Inc. (DASH) Stock Price, Quote & News - Stock Analysis
Locate At&T Store Near Me
Spoilers: Impact 1000 Taping Results For 9/14/2023 - PWMania - Wrestling News
St Maries Idaho Craigslist
Christina Steele And Nathaniel Hadley Novel
Why Should We Hire You? - Professional Answers for 2024
Boston Dynamics’ new humanoid moves like no robot you’ve ever seen
Craigslist Wilkes Barre Pa Pets
Afni Collections
Rural King Credit Card Minimum Credit Score
Tom Thumb Direct2Hr
Schooology Fcps
Delta Math Login With Google
Astro Seek Asteroid Chart
Mark Ronchetti Daughters
Craigslist Gigs Norfolk
P3P Orthrus With Dodge Slash
Diana Lolalytics
Levothyroxine Ati Template
Gvod 6014
Gt500 Forums
sacramento for sale by owner "boats" - craigslist
The Angel Next Door Spoils Me Rotten Gogoanime
Chathuram Movie Download
Former Employees
How I Passed the AZ-900 Microsoft Azure Fundamentals Exam
Hanco*ck County Ms Busted Newspaper
Elven Steel Ore Sun Haven
American Bully Puppies for Sale | Lancaster Puppies
Zom 100 Mbti
Dancing Bear - House Party! ID ? Brunette in hardcore action
Egg Inc Wiki
Online TikTok Voice Generator | Accurate & Realistic
Grace Charis Shagmag
Adams County 911 Live Incident
7 National Titles Forum
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.