1 00:00:07,940 --> 00:00:13,155 So let's demystify the Python runtime environment a bit. 2 00:00:13,155 --> 00:00:15,150 Up until now, you've been learning 3 00:00:15,150 --> 00:00:17,250 how the code itself works. 4 00:00:17,250 --> 00:00:19,860 That is, how the Python interpreter, 5 00:00:19,860 --> 00:00:21,510 which is a computational process 6 00:00:21,510 --> 00:00:23,400 running on your computer, 7 00:00:23,400 --> 00:00:26,850 considers the commands you give it, which are loops, 8 00:00:26,850 --> 00:00:29,865 control structures, variables, functions, 9 00:00:29,865 --> 00:00:31,350 and how it executes 10 00:00:31,350 --> 00:00:35,955 the underlying code on hardware such as the processor, 11 00:00:35,955 --> 00:00:38,820 video card, and memory of your computer, 12 00:00:38,820 --> 00:00:41,415 to create some experience for the user. 13 00:00:41,415 --> 00:00:43,160 In much of this course, 14 00:00:43,160 --> 00:00:46,280 you've been using a web-based simulation environment, 15 00:00:46,280 --> 00:00:49,990 Runestone, to create these experiences. 16 00:00:49,990 --> 00:00:52,250 With Jupyter though, we'll be using 17 00:00:52,250 --> 00:00:54,320 an environment that is more traditional. 18 00:00:54,320 --> 00:00:57,020 A key aspect of this traditional environment 19 00:00:57,020 --> 00:01:00,155 are the installation files for Python itself. 20 00:01:00,155 --> 00:01:03,890 Let's take a look. I'm going to open up a new terminal. 21 00:01:03,890 --> 00:01:06,320 Don't worry if this seems unfamiliar to you, 22 00:01:06,320 --> 00:01:08,630 we won't be using the terminal much in this course. 23 00:01:08,630 --> 00:01:12,215 I just want to help you explore the Jupyter system a bit. 24 00:01:12,215 --> 00:01:14,120 You'll notice that there are a bunch of 25 00:01:14,120 --> 00:01:16,550 characters when we open up the terminal. 26 00:01:16,550 --> 00:01:19,395 The first set of characters are username. 27 00:01:19,395 --> 00:01:20,520 You could ignore this. 28 00:01:20,520 --> 00:01:24,485 It should be the same Jovyan for all Coursera users. 29 00:01:24,485 --> 00:01:26,405 Then there's an at sign, 30 00:01:26,405 --> 00:01:29,230 and the next set of characters, are the machine name. 31 00:01:29,230 --> 00:01:31,115 Again, the machine name is just 32 00:01:31,115 --> 00:01:33,620 auto-generated by the Coursera system, 33 00:01:33,620 --> 00:01:36,920 and isn't really relevant for our discussion right now. 34 00:01:36,920 --> 00:01:39,680 Finally, the rest of the string is 35 00:01:39,680 --> 00:01:43,235 the current path or the location that we're working in. 36 00:01:43,235 --> 00:01:46,625 This is useful, and actually if we type the characters 37 00:01:46,625 --> 00:01:50,435 l and s in there for list and hit Enter, 38 00:01:50,435 --> 00:01:52,384 we'll see a list of all files 39 00:01:52,384 --> 00:01:55,235 and sub folders in this directory. 40 00:01:55,235 --> 00:01:57,260 But I actually want to show you where 41 00:01:57,260 --> 00:01:59,600 Python lives on this machine. 42 00:01:59,600 --> 00:02:01,070 So we're going to change 43 00:02:01,070 --> 00:02:03,635 the directory with the command cd. 44 00:02:03,635 --> 00:02:05,200 On the Coursera system, 45 00:02:05,200 --> 00:02:07,640 we're using a specific installation 46 00:02:07,640 --> 00:02:09,815 for Python called Anaconda. 47 00:02:09,815 --> 00:02:11,840 Don't worry too much about that. 48 00:02:11,840 --> 00:02:15,080 Let's just change to the site-packages directory. 49 00:02:15,080 --> 00:02:19,310 This is the real heart of the Python library ecosystem. 50 00:02:19,310 --> 00:02:26,290 So I'll go cd/opt/Conda/lib/ Python3.7/site-packages. 51 00:02:26,290 --> 00:02:28,120 When we do this, 52 00:02:28,120 --> 00:02:29,610 then do a directory listing, 53 00:02:29,610 --> 00:02:31,430 we see a whole bunch of things. 54 00:02:31,430 --> 00:02:32,930 First, there's a lot of 55 00:02:32,930 --> 00:02:35,310 interesting files and directories in here. 56 00:02:35,310 --> 00:02:38,000 These are the third party packages for Python, 57 00:02:38,000 --> 00:02:39,935 which are installed on the system. 58 00:02:39,935 --> 00:02:42,980 We're going to be dealing with a lot of new packages, 59 00:02:42,980 --> 00:02:46,000 but I want you to feel empowered to explore a bit. 60 00:02:46,000 --> 00:02:48,895 These packages are just Python files, 61 00:02:48,895 --> 00:02:51,050 or sometimes other languages as well, 62 00:02:51,050 --> 00:02:52,700 which have been configured to work with 63 00:02:52,700 --> 00:02:55,115 the current Python environment. 64 00:02:55,115 --> 00:02:57,140 Let's take a look at one that I'm 65 00:02:57,140 --> 00:02:59,315 familiar with called pillow. 66 00:02:59,315 --> 00:03:02,690 Pillow is an imaging library for Python. 67 00:03:02,690 --> 00:03:04,610 We can see that it's installed here 68 00:03:04,610 --> 00:03:07,100 because there's a pillow egg file. 69 00:03:07,100 --> 00:03:10,190 We can actually look at the source code of 70 00:03:10,190 --> 00:03:13,505 the Pillow library by going into the pill directory. 71 00:03:13,505 --> 00:03:15,995 So let's cd PIL. 72 00:03:15,995 --> 00:03:18,515 You'll see that when we do an ls, 73 00:03:18,515 --> 00:03:21,760 most of these files are just dot py files. 74 00:03:21,760 --> 00:03:23,905 Python code itself. 75 00:03:23,905 --> 00:03:27,800 We can even take a look at the Python source code behind 76 00:03:27,800 --> 00:03:31,505 this library using the more command here. 77 00:03:31,505 --> 00:03:33,470 Let's look at the main python file in 78 00:03:33,470 --> 00:03:35,900 this library called image.py. 79 00:03:35,900 --> 00:03:38,705 So more image.py. 80 00:03:38,705 --> 00:03:41,870 We can see that there's a bunch of comments at the top 81 00:03:41,870 --> 00:03:44,855 reaching all the way back to 1995. 82 00:03:44,855 --> 00:03:47,240 We see a few import statements, 83 00:03:47,240 --> 00:03:50,345 then some top-level variables like a logger. 84 00:03:50,345 --> 00:03:52,790 We won't talk much about loggers, 85 00:03:52,790 --> 00:03:55,415 but they're handy when debugging code. 86 00:03:55,415 --> 00:03:57,860 Then we see that there are a few classes 87 00:03:57,860 --> 00:03:58,880 which are created, 88 00:03:58,880 --> 00:04:00,545 then a math expression, 89 00:04:00,545 --> 00:04:03,695 then a try and except block, and so forth. 90 00:04:03,695 --> 00:04:05,600 You can feel free to explore 91 00:04:05,600 --> 00:04:08,750 this library more by hitting the space bar, 92 00:04:08,750 --> 00:04:13,590 or you can exit with more command by hitting q. 93 00:04:13,720 --> 00:04:16,970 So that's a very brief overview of 94 00:04:16,970 --> 00:04:20,165 where Python libraries exist on your system. 95 00:04:20,165 --> 00:04:22,850 Now, that's not exactly a user friendly way to 96 00:04:22,850 --> 00:04:26,060 interact with the library by reading the source code, 97 00:04:26,060 --> 00:04:29,000 but it's a great way to learn how libraries work, 98 00:04:29,000 --> 00:04:33,260 and how programmers create complex Python solution. 99 00:04:33,260 --> 00:04:36,110 But let's go back into the Jupyter notebook and 100 00:04:36,110 --> 00:04:39,930 explore how to actually use this library.