WEBVTT 1 00:00:00.130 --> 00:00:01.250 Hi and welcome back. 2 00:00:01.250 --> 00:00:04.650 In this video, we're just going to be setting up our project 3 00:00:04.650 --> 00:00:07.190 that we're going to be creating in this section. 4 00:00:07.190 --> 00:00:11.230 I've created a folder here in my documents 5 00:00:11.230 --> 00:00:12.390 and the only thing you need 6 00:00:12.390 --> 00:00:14.690 is to create a folder for your project, 7 00:00:14.690 --> 00:00:17.400 then remember where the folder is 8 00:00:17.400 --> 00:00:20.720 so that you can find it in your terminal. 9 00:00:20.720 --> 00:00:23.370 Once you created a folder for your project, 10 00:00:23.370 --> 00:00:24.970 let's go into the terminal 11 00:00:24.970 --> 00:00:28.230 and create our environment using Pipenv. 12 00:00:29.150 --> 00:00:31.790 Okay, once you are in your terminal, 13 00:00:31.790 --> 00:00:34.540 let's go into this directory. 14 00:00:34.540 --> 00:00:38.720 Remember on Unix systems like Mac OS X and Linux, 15 00:00:38.720 --> 00:00:43.090 we're gonna do cd and then find the folder. 16 00:00:43.090 --> 00:00:44.740 In Windows, you're gonna do chdir 17 00:00:45.710 --> 00:00:48.380 and then you're gonna find the folder like C:\ 18 00:00:48.380 --> 00:00:51.150 wherever the folder is. 19 00:00:51.150 --> 00:00:54.780 Here the folder is in my Documents/teclado-projects 20 00:00:54.780 --> 00:00:56.250 /your-first-flask-app/ 21 00:00:56.250 --> 00:00:57.680 so we're gonna cd into that 22 00:00:58.840 --> 00:01:03.750 and then we're going to use pipenv to instal Flask. 23 00:01:04.760 --> 00:01:07.790 Flask is the library we're going to be using in this section 24 00:01:07.790 --> 00:01:09.150 to create our website. 25 00:01:09.150 --> 00:01:10.550 It's a really lightweight library. 26 00:01:10.550 --> 00:01:12.880 We're gonna learn a lot about how it works 27 00:01:12.880 --> 00:01:14.890 throughout this section. 28 00:01:14.890 --> 00:01:17.260 Once you do pipenv instal Flask, 29 00:01:17.260 --> 00:01:20.030 make sure that it is creating a virtual environment 30 00:01:20.030 --> 00:01:22.530 using the correct version of Python, 31 00:01:22.530 --> 00:01:24.260 in this case Python 3.7. 32 00:01:24.260 --> 00:01:25.270 I know you can't see that very well, 33 00:01:25.270 --> 00:01:27.700 but version 3.7 there. 34 00:01:27.700 --> 00:01:30.210 3.6 is fine, 3.5. 35 00:01:30.210 --> 00:01:32.020 Just don't go under 3 36 00:01:33.640 --> 00:01:36.930 just because of some of the syntax we're gonna be using. 37 00:01:36.930 --> 00:01:38.420 Once it's installed, 38 00:01:38.420 --> 00:01:41.790 you'll have a virtual environment created as well. 39 00:01:41.790 --> 00:01:43.000 You know this already. 40 00:01:43.000 --> 00:01:45.610 Pipenv creates a virtual environment for you. 41 00:01:46.980 --> 00:01:48.370 Remembering this virtual environment 42 00:01:48.370 --> 00:01:49.690 is gonna be very important 43 00:01:49.690 --> 00:01:52.390 because we're gonna need to give it to PyCharm 44 00:01:52.390 --> 00:01:56.750 in order for PyCharm to use the correct Python version. 45 00:01:56.750 --> 00:01:59.060 Okay, so now that we've got this created, 46 00:01:59.060 --> 00:02:03.290 we've got, if we do ls or dir in Windows, 47 00:02:03.290 --> 00:02:06.490 we've got a Pipfile and that Pipfile.lock. 48 00:02:06.490 --> 00:02:07.323 They're under the Pipfile. 49 00:02:07.323 --> 00:02:10.160 It gives us what libraries we're installing. 50 00:02:10.160 --> 00:02:12.530 Pipfile.lock gives us a bit of security 51 00:02:12.530 --> 00:02:14.550 and also instals the correct versions. 52 00:02:15.520 --> 00:02:17.350 If we share both with other people, 53 00:02:17.350 --> 00:02:20.350 then they'll be able to instal exactly the same versions 54 00:02:20.350 --> 00:02:22.600 that we installed when we set up the project. 55 00:02:23.850 --> 00:02:25.050 Now that we've got this, 56 00:02:25.050 --> 00:02:28.460 again remember the location of this virtual environment, 57 00:02:28.460 --> 00:02:31.350 and let's go over to PyCharm to create our new project. 58 00:02:32.500 --> 00:02:35.130 Once you've opened PyCharm, you'll see a window like this. 59 00:02:35.130 --> 00:02:37.230 Just create a new project 60 00:02:37.230 --> 00:02:40.820 and here make sure to select the location of your project. 61 00:02:40.820 --> 00:02:45.760 So in my case, this is in my Documents/teclado-projects 62 00:02:48.250 --> 00:02:49.930 /your-first-flask-app. 63 00:02:51.120 --> 00:02:52.790 Be sure to select this folder 64 00:02:53.820 --> 00:02:55.720 and then in the interpreter, 65 00:02:55.720 --> 00:02:58.780 let's go and find the virtual environment 66 00:02:58.780 --> 00:03:01.570 that was created for us by Pipenv. 67 00:03:01.570 --> 00:03:03.100 Notice when I open this here, 68 00:03:03.100 --> 00:03:04.500 I get a lot of virtual environments 69 00:03:04.500 --> 00:03:06.000 in various different places. 70 00:03:07.200 --> 00:03:10.310 We're gonna need to go and add a local virtual environment 71 00:03:11.570 --> 00:03:14.120 and then find the virtual environment that we had before 72 00:03:14.120 --> 00:03:16.550 so going back over to the terminal, 73 00:03:16.550 --> 00:03:21.550 in my case this is in /users/jslvtr.local and so forth. 74 00:03:21.860 --> 00:03:24.330 So PyCharm allows you to copy this 75 00:03:25.470 --> 00:03:27.520 and then just put it in here in the path. 76 00:03:28.440 --> 00:03:30.090 This is the virtual environment. 77 00:03:30.090 --> 00:03:32.340 Then you're gonna open it up, 78 00:03:32.340 --> 00:03:34.140 find the bin folder, 79 00:03:34.140 --> 00:03:36.410 and find python. 80 00:03:36.410 --> 00:03:39.590 Okay, make sure to select python inside the bin folder 81 00:03:39.590 --> 00:03:42.550 and then press OK and now PyCharm knows 82 00:03:42.550 --> 00:03:44.910 that this is the Python version you want to use. 83 00:03:44.910 --> 00:03:48.580 It's gonna allow you to use Python 3.7 syntax. 84 00:03:48.580 --> 00:03:50.870 It's going to use the packages that are installed 85 00:03:50.870 --> 00:03:54.810 in this interpreter and not in the system Python. 86 00:03:54.810 --> 00:03:56.980 Then we can press create and it will ask us 87 00:03:56.980 --> 00:04:00.230 whether we want to create a project from existing sources. 88 00:04:00.230 --> 00:04:02.740 That's because we've got the Pipfile and the Pipfile.lock 89 00:04:02.740 --> 00:04:05.140 in there already and we're gonna say yes 90 00:04:06.880 --> 00:04:09.480 and then we're going to get our new project 91 00:04:09.480 --> 00:04:11.460 that has our two files there already. 92 00:04:13.030 --> 00:04:15.580 Whenever you want to instal new libraries, 93 00:04:15.580 --> 00:04:18.100 now you must not go through 94 00:04:18.100 --> 00:04:19.850 or you could go through the PyCharm 95 00:04:21.210 --> 00:04:23.660 settings here, this thing here, 96 00:04:23.660 --> 00:04:27.200 but I'd recommend you go through the Pipenv settings 97 00:04:27.200 --> 00:04:28.410 using the terminal. 98 00:04:28.410 --> 00:04:30.140 That's because this is going to instal something 99 00:04:30.140 --> 00:04:32.080 directly in the virtual environment, 100 00:04:32.080 --> 00:04:34.770 but it's not going to update your Pipfile. 101 00:04:34.770 --> 00:04:36.770 So if you want to instal more things, 102 00:04:36.770 --> 00:04:38.490 you can go through PyCharm, 103 00:04:38.490 --> 00:04:41.410 but you probably want to go through the terminal. 104 00:04:41.410 --> 00:04:44.590 Just do pipenv instal whatever else you need. 105 00:04:44.590 --> 00:04:46.430 For this project, we're not gonna need anything else 106 00:04:46.430 --> 00:04:50.030 so Flask is the only thing we need and we've got that now. 107 00:04:50.030 --> 00:04:54.600 If you create a new Python file and you call it app.py, 108 00:04:54.600 --> 00:04:58.270 you should be able to do from flask_import Flask. 109 00:04:58.270 --> 00:05:00.970 Okay, if this doesn't give you any errors, 110 00:05:00.970 --> 00:05:02.540 then you're good to go. 111 00:05:02.540 --> 00:05:04.170 If this gives you any errors, 112 00:05:04.170 --> 00:05:06.810 just check your settings, check your Pipfile, 113 00:05:06.810 --> 00:05:08.630 make sure everything's setup correctly. 114 00:05:08.630 --> 00:05:10.200 It's possible that 115 00:05:10.200 --> 00:05:11.990 either something wasn't installed correctly, 116 00:05:11.990 --> 00:05:15.120 in which case your Pipfile will not show Flask, 117 00:05:15.120 --> 00:05:17.190 or it's possible that 118 00:05:17.190 --> 00:05:20.060 you're not using the correct virtual environment, 119 00:05:20.060 --> 00:05:22.260 in which case you want to go back 120 00:05:22.260 --> 00:05:25.480 and make sure to select the correct virtual environment here 121 00:05:25.480 --> 00:05:28.970 or add a local virtual environment and find the correct one. 122 00:05:28.970 --> 00:05:31.840 Okay, make sure that Flask is here 123 00:05:31.840 --> 00:05:33.340 and then you can import Flask. 124 00:05:34.250 --> 00:05:35.390 Once that's all ready, 125 00:05:35.390 --> 00:05:36.710 you're good to continue into the next video 126 00:05:36.710 --> 00:05:38.230 where we're going to be implementing 127 00:05:38.230 --> 00:05:40.870 our first web application. 128 00:05:40.870 --> 00:05:41.820 I'll see you there.