Python Jumpstart by Building 10 Apps Transcripts
Chapter: App 5: Real-time weather client
Lecture: Concept: pip

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Our next concept is pip, or more generally
0:03 how do we get packages form this Python package index
0:06 installed into our local Python environment
0:09 so that we can use it with our applications.
0:11 One way the wrong way but a possibility would be to go to PyPi,
0:14 find the package, the zip file, download it,
0:18 decompress it and then run some Python commands to install it locally.
0:22 For simple packages that would work,
0:24 although there is a lot of drawbacks,
0:26 often these packages come with dependencies
0:29 here we are installing Requests, but Request itself doesn't have
0:32 any dependencies but many packages do,
0:35 that manual download and install doesn't account for installing the dependencies
0:40 and then the dependencies of the dependencies and on and on and on,
0:43 the entire dependency graph, but pip handles that for us.
0:46 Also, if you want to get an update to your package
0:48 or even ask the question is there an update for this package
0:52 the manual way doesn't do it, so pip is what you want to use,
0:55 and it's super easy to use, you just say pip install and the name of a package,
0:58 so go out to PyPi, look for that package download the latest version,
1:02 you can lock it to a version, there is a lot of options, things like this,
1:05 but it will download it download any dependencies
1:09 and then execute the setup part of the package
1:12 to install it successfully into whatever environment you want.
1:16 Now, depending on how your Python environment is set up,
1:20 and whether it's in your user profile or it's actually machine wide
1:24 you may have to run sudo pip install request
1:27 because it's making a change to the global machine wide Python install,
1:31 if you are on Windows, the equivalent of this would be to run the command prompt
1:35 as admin when you run this command.
1:37 It's worth pointing out that that could be a bad idea,
1:40 when you install packages with pip,
1:42 it downloads the package which is some random bit of code form PyPi
1:47 then it literally runs some code from that package on your machine
1:51 and if you use sudo, it runs it as root or admin,
1:55 which may or may not be ok
1:57 depending on how much you trust those packages
1:59 so just be aware of that consideration.
2:01 Two more quick things to note, one is if you have Python 2
2:04 you may not have pip and if you have an old version of Python 3
2:09 before 3.3 you also might not have Pip
2:12 so you can use that link above to install it
2:14 but if you have Python 3.3 or above you already have pip installed, that's excellent,
2:19 the other one is instead of using the public package repository on PyPi
2:23 you can actually create your own hosted internal package repository
2:28 and use pip to install and manage
2:31 say maybe private packages for within your company,
2:34 that's a pretty interesting way to manage libraries and packages
2:37 across teams in large companies.