Python Importing Module Section Introduction
Hi and welcome to this section where we're going to learn how to import modules inside of python.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

So far in this course, we've mainly been writing all of our own code. So anytime we wanted a piece of functionality such as building out some type of function we wrote all of the functionality inside of that.

However one of the best things about Python is that it has a massive community of developers and open source contributors who've built out some pretty amazing libraries. And so what we can do with Python is we can actually go into some of those libraries pull them down into our own programs and use them ourselves. And I think it kind of helps to have a visual. So before we go into the code we're going to draw exactly how modules work inside a python.

So far in this course, we have been working with the core Python library and so what that means is that in that library we have a set of functionality that we automatically have access to. So imagine when we went and we were using strings we could call the format method and then work with that without doing anything at all we could simply have a string and then just because we were working with the core language we could call format we didn't have to import any modules or anything like that.

large

Now, this is still within the base Python language if you remember back to the numbers section whenever we wanted to use some advanced math functions we had to perform an import. So here this is going to also be all within the core Python language but if we wanted one of the math libraries we had to import it and so if we wanted that into our probe in our main program right here we had to say import math.

large

And then from there, we could call the floor function or the cell function, and then we could use them exactly like how we did. Now those were still all within the core Python library. Now there is a very large ecosystem of other libraries out there. So that sits outside of the core language. So what that means is we can't simply call them the way we did with the math library before we can do that we need to import them into our own system.

There are a number of different names for this, this is the python package index which is just a fancy way to say they keep a database of all of the different modules that you want to import. For short it's usually called Pypi and then a little secret kind of code word that people use is they call it the cheese shop and if you're ever curious on why that is you can simply google Python Cheese Shop and you'll see it dates back to a popular SNL skit from decades ago. But if you'll hear all three of these terms I wanted you to be aware of them. Cheese Shop, Pypi, Python package index.

Now inside of this, it is going to contain a very large number of libraries. So you're going to have machine learning libraries. You'll have different ones for working with data structures all kinds of things you can imagine. Also when we get into frameworks such as Flask or Django these are all packages within this index right here. And so what we need to do in order to call those is we need a connection here and that's what we're going to go through throughout this section.

Now the connector is called Pip and that is going to give us a direct feed into this entire database and then we can simply install those libraries on our system and then we can call them exactly the same way we did with the math library.

large

So that is a very high-level overview of the architecture and how packages and modules are structured three ways One where you have direct access. Another where they're in the core language but you still need to import them. And then the third where you have third party types of libraries that need to be manually installed.