Python Tutorial: pip - An in-depth look at the package management system
9:06

Python Tutorial: pip - An in-depth look at the package management system

Corey Schafer 16.04.2015 281 206 просмотров 4 310 лайков

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI
Описание видео
In this video, we will take an in-depth look at Python's package management system, pip. We'll walk through how to install, uninstall, list, and upgrade packages. We will also dive into how we can output our dependencies and install a list of dependencies. An in-depth knowledge of pip can be a great addition to your Python tool-belt. ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/ #Python

Оглавление (9 сегментов)

<Untitled Chapter 1>

hey what's going on everybody uh today I wanted to take a look at the python package manager pip and also go over some of the most frequent commands that you're going to use uh whenever uh you start the use pip um so with that let's uh go ahead and get started so first things first one of the best resources is if you just type in PIP help then it will bring up all the commands and options that you can use uh so you can see here there's not a whole lot but um it shows you um install uninstall freeze and also uh some of the options that you can use um also uh with that we can also do a pip help and then we can type in a specific command so if I type in PIP help install now it's going to bring up

bring up the options for install

the options for install so you can see here um that we have a Tac R for a requirements file um you can do an upgrade and also install things uh per us user basis and things like that so with the help files out of the way uh let's go ahead and take a look at how we'll actually use this um so say you want to find a package um if you're looking for a package and you don't know exactly what it's called you can just do a pip search um so let's say I on this package and it is going to return to me the package name and also a description of the package here um so once you find the package name then you can go ahead and install it so I'll do a pip install and choose the package that we searched for and now you can say see that it says that this was successfully installed um so if we want to take a

at our install packages

look at our installed packages we can do a pip list and it will show us all the packages that we currently have installed so you can see here this is the package that we just installed um if we don't want that package we can do a pip uninstall and choose that package and then it's going to ask us if we want to continue hit yes now you can see that it's successfully uninstalled and now let's do another pip list and you can see that package that we just uninstalled is no longer listed another thing you'll notice whenever it lists packages it lists the package and it lists the version number uh so how do you know if this version is the latest version of this package um well with Pip list we can do a TCT Tac outdated or we can just do a single Dash with an O hit enter and now you can see one of our

running the latest version of the package

packages uh isn't running the latest version of the package uh the setup tools uh the current version that we have installed is uh 12 and the latest is 15 um so to update this package what we'll do is a pip install and then an uppercase U for upgrade and then we can type in the package now you can see that was successfully installed if I do a pip list of the packages now you can see that our setup tools is at the latest version now for demonstration purposes uh let me go ahead and reinstall the package that we uninstalled a little bit ago and now if I do a pip list now let's say that you're working on a project and you want to uh provide maybe somebody else who wants to work on the project you want to provide them with a

provide them with a list of all the packages

list of all the packages that they need for that project um now one thing you could do is just type out pip list and then they could manually copy down all of those packages and version numbers and install them that way but if you have a really long list of packages then this definitely isn't the best way to do it for this we're going to use something called uh freeze command if we type in PIP freeze and what this does is it outputs

outputs all of our packages and version numbers in a requirements format

all of our packages and version numbers in a requirements format um so if we wanted to uh send this to somebody then what we could do is pipe this or actually output this uh to a requirements file so I can type in requirements. txt and hit enter now if I do cat requirements. txt you can see that it lists our package and version number so if you were to send this requirements text file to somebody uh how would they install all those packages using pip um well I have a sample file here that I'm going to use this R test. txt and you can see I have a few packages listed here so let's say I wanted to install all of these packages now the way you would do this is you would type in PIP install and then attack R and what the r is it's saying hey we're going to use a requirements file and the name of this file is RoR test. txt hit enter and it's going to go through install all those packages and that version of that package now that those are finished installing if I do a pip list then you can see it has installed all those packages at the um exact same version number that was in the requirements file now those simple Basics are pretty much um what you're going to use pip for most of the time um but I do want to show you one last trick here um these packages that I just installed if I do a pip list outdated now you can see I have multiple packages here that are out of date now I could go through and do uh pip currently

a way to upgrade all packages

doesn't have a way to upgrade all packages that need upgraded um you could go through and do each one of these manually uh but if you have a lot of packages then you know that could be a lot of time to waste um so on stack Overflow uh there uh is an answer here by RBP and he gives this good command here that will go through and do this for you so let me paste this in and walk through exactly what it does okay so first we have Pip freeze which outputs

outputs all of the requirements for the packages

all of the requirements uh for the packages that we currently have uh this TCT Tac local here um if you're in a virtual environment that has access to your Global packages then it'll only print out local packages and then you pipe that output to this grep command here and actually I'm not entirely sure what this grep command does I think he has it uh listed on his answer over here um so this skips - e package definitions um I've never run into that but um maybe it's uh useful for some cases so then after it runs to that GP command then it gets piped in to this uh cut command here and what this cut command does is it sets the delimer to an equal sign and uh then it only returns uh the first uh argument back of that result um so let's see exactly what that would look like here so if I go all the way back here to this GP command and hit enter Then you can see it outputs all of these requirements files with these equals and then the version number and whenever you add in that cut command um all it does is it will cut out after or before the uh equal sign there and only return the package name so now we have a list of all of our packages and then lastly the last part of the command um takes this output as arguments one at a time and runs that to the command pip install Tac U which we went over earlier which is upgrade and that will go through and upgrade every one of the packages that uh we had outputed so if I hit enter there now you can see that it's going through each package that needed upgraded and is doing so now after that's finished updating if I do a pip list you can see the list of

see the list of all of our packages

all our packages and uh version numbers if I do a pip list outdated then we shouldn't have any listed yep and it returned um with no packages that need an upgrade so that about does it I hope that this uh quick overview of pip was useful for you guys um if you do have any questions just feel free to leave those in the comment section below um be sure to subscribe for future tips and tutorials and thank you for watching

Другие видео автора — Corey Schafer

Ctrl+V

Экстракт Знаний в Telegram

Экстракты и дистилляты из лучших YouTube-каналов — сразу после публикации.

Подписаться

Дайджест Экстрактов

Лучшие методички за неделю — каждый понедельник