Installing Packages With pip Practice: Python Basics Exercises
Key Takeaways
The video demonstrates how to install packages using pip, including listing installed packages, creating virtual environments, and freezing package versions. It covers the basics of package management in Python using pip and virtual environments.
Full Transcript
hello hello hello I'm philli with real python and I'm so excited that you're joining me today on this very special course in this real python exercises course you'll practice installing packages with Pip our exercises courses are all about training you'll train the process of writing code by solving carefully selected exercises you'll also train reading over other people's code and communicating your thought process doing all that you'll practice the concepts that you've learned about in an Associated course or tutorial and help make them stick in the upcoming lessons I'll introduce you to tasks give you an opportunity to solve them yourself and then show you step by step how I solved each of them you'll go through three steps for each task learn about the exercise code your own solution and then you'll compare Your solution with mine when I walk you through a task I'll explain what I do do and also why I do it like that that will give you a chance to compare not just our final solution but also how we got there you'll start with solving some review exercises in the first section and then slowly you'll build up towards a proper challenge before starting this course you should have watched the python Basics course on installing packages with Pip if you went through that course then you're well equipped to solve the tasks that I'll throw at you in this course the concepts that you practice are using the terminal working with virtual environments installing packages and declaring project requirements if you're somewhat familiar with these Concepts and you want to strengthen your knowledge with some practical programming tasks then this course is exactly right for you if you're ready to get started and do some Hands-On programming then see you in the next lesson there I'll introduce you to the first exercise to get get you warmed up welcome to the first exercise in this exercise you need to list your packages it's a good idea to open the terminal because that's what you need for this one and your task is to list your currently installed python packages with the PIP command in your terminal you can pause this video course and then try to solve the exercise on your own and once you're ready move on to the next lesson where you see how I solve this exercise I'm here in my terminal right now so make sure that you also try this in your terminal and not in your python console in idle or something like that so it's important that you're using the terminal to list all the packages that are currently installed on your systemwide python you use Python 3-m pip and then you use the list command if the Python 3 command doesn't work on your system you might try to only write python if you're still struggling just let us know in the comments below and we will help you out or refer to the installing python python Basics video course that I mentioned at the beginning of this course and once you press enter you see all the packages with their versions that are currently installed in your Python 3 installation on my system these packages are probably a bit different than on your end but we will tackle this with virtual environments in one of the next lessons there's another thing I want to show you for the moment and that's if you use the arrow up you can go back to a command that you used before if you were unsure which command you Ed to list the packages you can always use dashh the H stands for help and instead of writing DH you could also write [Music] d-el so I used the arrow up to go to my former command so I don't have to type everything and then I remove the list command with Dash and once you press enter you get a big bunch of information and that's all the flags and commands that pip supports so if you are unsure about certain pip commands - H is always a good idea and with this let's move on to the next exercise task here is way more text on the slide than the formal exercise so it's a bit more work to do for you in your terminal application navigate to your desktop and create a new folder named pipore exercises then change into the newly created folder and print your current working directory after that navigate back to the desktop folder and create another folder named other uncore exercises so the other exercises folder should be next next to the PIP exercises folder verify that both folders Exist by listing the items on your desktop here I am again in my terminal that's what you see on the left side and basically I will be in the terminal for all the exercises so I probably won't mention it in the future exercises but this time on the right side you also see my file explorer the reason why I'm doing this is that we are seeing in live what changes I am doing in a terminal so we could check everything in the terminal with commands as well but it's nice to have it a bit more visual for this course the first thing we need to do is to navigate to the desktop to navigate in the file system in the terminal you use the CD command CD stands for change directory but the CD command alone doesn't do anything because you need to tell the terminal where you want to go and now there is one cool short hand on Unix systems where you can use the Tilda character followed by a slash and that's basically your user directory and when I want to go to desktop I use the Tia slash and then desktop with the CD commands before that and once I press enter I'm going to the desktop how do I know if I'm on the desktop now there is another command PWD PWD stands for print workking directory and that shows me the F so now we can be sure that we're on the desktop and the next part was to create a directory named pip uncore exercises for this I use MK deer then a space pip uncore exercises and once I press enter you see on the right side of the screen that there is a new folder named pip exercises in the file explorer so cool that worked now change into the newly created folder and print the current working directory the command to print the current working directory you already know and also you basically know how to move into a folder so this should be nothing new to you it's CD and then you use the folder name that you just created and here I can use another trick and that's starting with a name that exists in that folder and press tap and then the terminal autoc completes if it finds something so in this case this pip exercis folder exists and once I CD in it I can do PWD and that prints the current working directory which now is the PIP exercises folder on the desktop to move back to the desktop I can use CD and now I could use the till the desktop command but I can also use dot dot which is the Parent Directory link once I press enter and use PWD you can see that I moved back to desktop and from there we should create another folder named other underscore exercises once I press enter you can see on the right the folder got created and with ls I can list all the folders in the terminal as well this concludes this exercise now it's time to work with a virtual environment inside your pip exercises folder create a virtual environment named ven that's venv verify that the virtual environment exists by listing the items in the directory then activate the virtual environment okay it's finally time to work with virtual environments we need to create a virtual environments inside the PIP exercises folder let's see where we are right now by typing PWD so I'm on the desktop and with ls I can see that there is a pip exercises folder so I can CD into this folder and to check if I'm into this folder I use PWD again which verifies we navigate into the PIP exercises folder and then we create a virtual environment named V and we can do this by using python 3-m and then you call the ven module and you create a virtual environment named Ven and once you press enter your computer probably works a little bit to create it and if you press LS you can see that there is now a v folder in your pip exercises folder since I have my file explorer open on the right side I can also click this little arrow here and you can see see that there is the virtual environment folder successfully created but it's not just a folder there is a bunch of stuff in this folder so let's click this one here and as you can see there are a few folders in there but you don't need to bother that much about it the important thing is you have this virtual environment folder now but to actually work with the virtual environment you need to activate it so let's go back to the terminal and activate the virtual environment and this you do with source and then ven that's the virtual environment folder bin SL activate and once you press enter you can see on the left side that there is ven in parentheses now at the left side of your prompt and this indicates that you successfully activated the virtual environment on Windows you execute WTH back slash scripts back slash activate inside the PIP exercises folder install the rich package that's r i in your activated virtual environment then freeze all your requirements in a requirements.txt file the important part here is that you install the rich package into an activated wi environment because if you don't activate your virtual environment you will install it into your systems python packages but you want to install the rich package only into your virtual environment so make sure to activate it first now you can go on and solve this exercise on your own and I will wait for you in the next lesson where you will see how I solve this exercise we're definitely heating up with the exercises but for now it's time to do some freezing see what I did there but before that we need to install the Rich package now before you install the rich package you really must make sure that you activated your virtual environment before you can verify that by looking for the v in parenthesis in front of your prompt so again you use Python 3-m pip and then install Rich which is r i and you press enter you're downloading it and you may also get a warning message that you're using an older version of pip and then you get an information which command you should use to upgrade it you know what let's do this as well python 3-m pip install and that works because pip is basically a python package so you can also use pip install on pip itself since you already have installed it you you need to use the upgrade flag and then pip Python 3-m pip install D- upgrade pip and when you press enter you're downloading the current version of pip but this exercise works with the older one as well we're not doing fancy stuff here so next you need to freeze finally the current packages of your virtual environment and you do this by typing python 3-m pip and then you use the freeze command oh and by the way if we're talking about freezing it's actually just another term for pinning project dependencies and if you just type this freeze command let's try it if you press enter Then you can see that pip prints you the currently installed packages with their version numbers it's similar to your pip list command that you use in a former exercise but this one has already the formatting that pip uses to install packages you can use the arrow up again to go to the former command and now you want to save the output of this command in a file and this you do by using the greater than symbol and then you define a fire name which is commonly requirements.txt that's also what is expected from us in this task and once you press enter you see there is no terminal output but on the right side where you can see the file explorer there is now a requirements.txt file that contains the output from pip freeze
Original Description
This is a preview of Python Basics Exercises: Installing Packages With pip. Many programming languages offer a package manager that automates the process of installing, upgrading, and removing third-party packages. Python is no exception. The de facto package manager for Python is called pip.
In this preview you’ll test and reinforce your knowledge of installing packages and managing virtual environments.
This is a portion of the complete course, which you can find here:
https://realpython.com/courses/basics-exercises-install-packages-with-pip/
The rest of the course covers:
- You will be challenge to re-create a development environment
- Freeze project requirements
- Troubleshoot as you work through the challenge
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Real Python · Real Python · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A better Python REPL – bpython vs python interpreter
Real Python
Introducing large-type.com – A Utility Website
Real Python
Reading Hacker News Without Wasting Tons of Time
Real Python
Forward References and Python 3 Type Hints
Real Python
Using Sublime Text as your Git Editor
Real Python
Python Code Linting and Auto-Complete for Sublime Text
Real Python
Make your Python Code More Readable with Custom Exceptions
Real Python
Write Better Tests with Sublime Text's Split Layout Feature
Real Python
How to Use Sublime Text from the Command Line
Real Python
Rename Variables with Multiple Selection in Sublime Text
Real Python
Sublime Text Settings for Writing PEP 8 Python
Real Python
Write Cleaner Python with Sublime Text's Indent Guides
Real Python
Sublime Text Whitespace Settings for Python Development
Real Python
Function Argument Unpacking in Python
Real Python
Python Code Review: Debugging and Refactoring "Conway's Game of Life" + Automated Tests
Real Python
Using "get()" to Return a Default Value from a Python Dict
Real Python
A Python Shorthand for Swapping Two Variables
Real Python
Python Code Review: Refactoring a Web Scraper, PEP 8 Style Guide Compliance, requirements.txt
Real Python
Click & Jump to Test Failures from the Command Line (iTerm2)
Real Python
Setting up Sublime Text for Python Developers
Real Python
Sublime Text + Python Guide Overview
Real Python
Python Code Review: Adding Pytest Tests to an Existing Python Web Scraper
Real Python
Type-Checking Python Programs With Type Hints and mypy
Real Python
A Shorthand for Merging Dictionaries in Python 3.5+
Real Python
Python Code Review Flask Web Security Tutorial + Virtualenvs, requirements.txt
Real Python
My Python Code Looks Ugly and Confusing – Help!
Real Python
Setting Up a Programmer Portfolio/Developer Blog – How To Get Started
Real Python
Do I Need a GitHub/GitLab/Bitbucket Profile as a Developer?
Real Python
Programmer Portfolio – Example and Walkthrough
Real Python
How to Get Your 1st Speaking Gig at a Tech Conference
Real Python
How to Build Your Public Speaking Skills as a Developer
Real Python
The Object-oriented Version of "Spaghetti Code" is "Lasagna Code" ?!
Real Python
Setting up Sublime Text for Python Developers – Lesson #1
Real Python
Cool New Features in Python 3.6
Real Python
"is" vs "==" in Python – What's the Difference? (And When to Use Each)
Real Python
Emulating switch/case Statements in Python with Dictionaries
Real Python
Python Function Argument Unpacking Tutorial (* and ** Operators)
Real Python
What Code Should I Put On My GitHub/GitLab/BitBucket Profile?
Real Python
A Crazy Python Dictionary Expression ?!
Real Python
String Conversion in Python: When to Use __repr__ vs __str__
Real Python
Method Types in Python OOP: @classmethod, @staticmethod, and Instance Methods
Real Python
Optional Arguments in Python With *args and **kwargs
Real Python
Python Context Managers and the "with" Statement (__enter__ & __exit__)
Real Python
Installing Python Packages with pip and virtualenv / venv
Real Python
"For Each" Loops in Python with enumerate() and range()
Real Python
Python Code Review: LibreOffice Automation and the Python Standard Library
Real Python
Managing Python Dependencies With Pip and Virtual Environments – Lesson #1
Real Python
Python Tutorial: List Comprehensions Step-By-Step
Real Python
Leveraging Python's Implicit "return None" Statements
Real Python
What's the meaning of underscores (_ & __) in Python variable names?
Real Python
Python Data Structures: Sets, Frozensets, and Multisets (Bags)
Real Python
Writing automated tests for Python command-line apps and scripts
Real Python
How to find great Python packages on PyPI, the Python Package Repository
Real Python
Immutable vs Mutable Objects in Python
Real Python
PyPI vs Warehouse, the Next-Generation Python Package Repository
Real Python
pep8.org — The Prettiest Way to View the PEP 8 Python Style Guide
Real Python
My Experience at PyCon 2017 in Portland
Real Python
Pylint Tutorial – How to Write Clean Python
Real Python
"Reverse a List in Python" Tutorial: Three Methods & How-to Demos
Real Python
Python Refactoring: "while True" Infinite Loops & The "input" Function
Real Python
More on: Tool Use & Function Calling
View skill →Related Reads
📰
📰
📰
📰
The no-code AI business stack that earns $5k/month on autopilot
Dev.to AI
GitHub’s April Changelog Exposes the Private-Repo Cost of Instant Reviews
Medium · AI
AI Did Not Kill Freelancing. It Changed What Clients Actually Pay For
Dev.to · Alcora
25 Best AI Tools in 2026 to Boost Productivity, Create Content & Make Money Online
Medium · Startup
🎓
Tutor Explanation
DeepCamp AI