Modern Python Projects Transcripts
Chapter: Python versions and packages
Lecture: The problem with pip

Login or purchase this course to watch this video and the rest of the course contents.
0:00 You often hear that python comes with batteries included.
0:03 This means that it comes with plenty of packages already installed.
0:07 This is called the Standard Python Library.
0:10 You can Goto Python Modules Index website,
0:12 and here you can find the list of all the packages that comes with python.
0:17 So, without installing anything, you can just import them in your code.
0:20 But what makes Python truly amazing is the Python Package Index.
0:25 This list of over 260,000 packages created by other developers.
0:32 If you find the module that you want to use,
0:34 all you need to do is to run pip,
0:36 install and the modules name, and this will download and install that package for you
0:41 Now you could import this module in your code and start using any function that
0:46 this module offers. With so many python packages,
0:50 you can quickly built a pretty advanced projects simply by combining different packages together.
0:56 However, pip has one big problem.
0:58 You can only have one version of a given package installed on your computer.
1:03 Whenever you ask it to install a specific version of a python package,
1:07 it will uninstall the previous versions from your computer and installed the one that you asked
1:12 for. Let me show you an example of what I mean.
1:16 Let's say you are a Web developer and you want to build a Django website,
1:20 so, you create a folder for the application and then you start by installing the latest
1:25 version of Django with pip install Django Command.
1:31 As you can see it, this installs Django 3.
1:34 Everything works great. You build an awesome website and it's actually so good that soon
1:40 you get a customer coming to you and asking to fix their Django website.
1:45 Their Django website is still running on Django to so you go out from this folder
1:50 you create a new one and then you installed Django 2 by specifying pip install django==2.2
1:56 Let's say, pip does what you ask for,
2:02 and after a few seconds you start working on your client's website using Django 2.2.
2:07 So far, so good. But later that day,
2:10 you discover a bug on your personal website,
2:12 the one that you created with Django 3.
2:15 You quickly fix the code, but when you want to test that is working correctly
2:18 you get error message saying that Django 2 is not installed.
2:22 What? Wait. But we just installed
2:24 a few days ago, where did it go?
2:26 Well, when we told pip to install Django 2.2 pip first checked if we already
2:32 have Django install and we did.
2:34 But it was not the 2.2 version,
2:36 so pip uninstalled that version and installed the correct one.
2:40 As you can see here, it says uninstalling Django 3 and successfully installed Django 2.
2:45 And if we check the list of packages installed on our computer,
2:50 you will see that we no longer have Django 3.
2:53 So, we just run into a problem with dependencies management.
2:57 All the python packages that you install with pip are called dependencies because the projects you
3:02 are building depends on them. pip installs those dependencies in the site packages folder and
3:08 puts each package in a separate folder named after the package.
3:13 So, when we installed Django 3, it was placed in site packages/django folder.
3:18 But when we tried to install Django 2,
3:21 it was also placed in the same folder,
3:24 so, pip has the first remove what's inside the Django folder and then install different version
3:29 of Django. If you're only working with one python project on your computer,
3:35 then you are probably not affected by this problem.
3:38 But sooner or later you will need to install a different version of a package,
3:42 and you're going to run into issues with pip uninstalling some previous dependencies.
3:48 Dependencies management problems are not specific.
3:51 to python. Basically, any programming language that allows installing external modules have to face
3:57 this issue, and different programming languages solve it in a different way.
4:02 For example, developers who used Ruby on rails install their packages with a tool called
4:06 bundler. And when Bundler installs a new dependency,
4:10 it puts it in a folder called Package Name-Version.
4:14 So it's possible to have two different versions of a package.
4:17 For example, here you can see we have active support 5.2.3 and 6.0
4:24 and so on.
4:29 JavaScript or, more specifically, node.
4:32 So, the server side version of JavaScript solves this problem by installing all the dependencies inside
4:38 the folder called node modules inside of your project.
4:42 So, each different project on your computer has a different folder where the dependencies are stored
4:49 right now, in Python pip doesn't have a good solution for this problem.
4:53 However, there is a proposal to use a local packages directory in the same manner
4:58 as JavaScript developers do. If it gets implemented,
5:01 pip would be installing all the dependencies in the folder inside of your project,
5:05 not globally. This proposal is still draft,
5:08 but maybe in a future version of python problem with dependencies will be solved.
5:13 But for now, most python developers solved this problem using virtual environments.