Standing on the shoulders of giants
One of Python’s superpowers is its massive collection of packages. Instead of writing everything from scratch, you can use code that others have already written, tested, and shared.What are packages?
Packages are collections of Python code that solve specific problems:- requests - Download web pages and data
- pandas - Work with spreadsheets and data
- numpy - Fast mathematical operations
- openai - Connect to AI models
- beautifulsoup4 - Extract data from websites
Meet pip
pip (Pip Installs Packages) is Python’s package manager. It:- Downloads packages from the internet
- Installs them in your environment
- Manages versions and dependencies
pip comes with Python, so you already have it! When you activated your virtual environment, you got your own copy of pip.
Your first package installation
Now we need to use the terminal - your command center for managing packages.Understanding the terminal
The terminal is where you type commands to control Python. Most of the time, VS Code handles everything automatically (like running your code). But for installing packages, we need to type commands ourselves. Open your terminal:- Keyboard shortcut: Press
Ctrl + `(Windows/Linux) orCmd + `(macOS) - Menu: View > Terminal
(.venv) at the beginning? That’s VS Code telling you “I’ve activated your virtual environment for you!” This means any packages you install will go into your project, not your computer’s main Python.
Install your first package
Let’s install therequests package:
What just happened?
No magic here! When you ranpip install requests, here’s what happened:
- pip connected to PyPI (Python Package Index) - a huge website where developers share their code
- Downloaded the requests package - just a bunch of Python files that someone else wrote
- Saved it in your
.venvfolder - specifically in.venv/lib/python3.x/site-packages/
Want to see the actual files? Look in your
.venv folder and navigate to lib > python3.x > site-packages > requests. It’s just Python files!Using installed packages
Now you can use this package in your Python code:See what’s installed
To check which packages you have:requests also installed other packages it needs (like urllib3). pip handles this automatically!
Install specific versions
Sometimes you need a specific version of a package:Uninstall packages
Made a mistake or no longer need something?Where packages come from
pip downloads packages from PyPI (Python Package Index), which hosts over 500,000 packages! Anyone can upload packages there, which is why Python has tools for everything.Common issues
pip: command not found
pip: command not found
Your virtual environment might not be activated:
- Check for
(.venv)in your terminal prompt - If missing, activate it using VS Code’s Python interpreter selection
- Or activate manually with the terminal commands from the previous section
Permission denied
Permission denied
You’re probably trying to install in system Python:
- Make sure your virtual environment is activated
- Never use
sudo pip install - Always see
(.venv)before installing
Package not found
Package not found
The package name might be different from what you expect:
- Check the exact name on pypi.org
- Example: “Beautiful Soup” is actually
beautifulsoup4 - Example: “OpenAI” is just
openai(lowercase)
Ready for interactive Python
Now that you understand packages, let’s install what we need for interactive Python mode!Interactive Python
Learn my favorite way to write Python code