Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Playing on the Same Team as the Import System

The good news is that you can play on the same team as the import system, by installing! In this lesson, you’ll learn what’s involved in installing and also get to see the advantages of installing. Specifically, installing gets you:

  • Consistent imports
  • Support for multiple packages

00:00 What we want to do is that we’ll find a way where things can work much more intuitively in a sense, and the way to do that is instead of trying kind of to sneak around Python’s import system, we’ll play on the same team as the import system essentially. That sounds good.

00:16 So what that entails is essentially that we’ll install our package. Install our package? Does that mean we have to upload something to PyPI and then download it with pip and stuff like that? Or what does that involve? So it does involve pip.

00:31 it means we’ll do pip install. But we don’t need to upload it anywhere. We can just have it locally. Most of the time you use pip install, you do like pip install pandas or pip install django, and it runs off on the Internet to find those things. But you can also just say, I wanna pip install my directory snakesay, and then that will happen without no one on the Internet seeing your code, and it’ll happen without you running off to the Internet. And it’ll make our lives easier.

00:57 It will our lives much easier because then we can just use consistent imports everywhere. Uh huh, and does that have any other advantages? One very cool thing is that now we’ve so far seen that we’re very dependent on where in the files tree we’re kind of running things from. Right, we have to make sure we’re in the right folder and using the right way to call the thing from the right place. Exactly. And say that we had a different project where we wanted a cute snake.

01:24 I would’ve had a really hard time to import snake from snakesay without at least doing some of these weird syspath things that we talked about.

01:33 But after I install it, it’ll actually be available from anywhere I run my code as long as it kind of installed into that environment. From anywhere, wow. Sounds like a superpower.

01:44 It is.

Become a Member to join the conversation.