Python for Entrepreneurs Transcripts
Chapter: Build web apps with Pyramid: Part 1
Lecture: CLI Demo

Login or purchase this course to watch this video and the rest of the course contents.
0:01 All right, it is time to create our project using the command line.
0:05 If you're going to use some editor that's not PyCharm professional,
0:09 this is really the way to do it, if you are going to use PyCharm pro,
0:12 you can still do it this way, and then just open the folder, and go with it there.
0:16 So what we're going to do is we're going to start by installing cookiecutter,
0:20 and then we're going to actually use cookiecutter to create the project.
0:25 So we are going to say pip install cookiecutter -u for upgrade
0:32 in case you already have it, and --user, so that it just installs for me,
0:36 it doesn't actually modify the system,
0:39 and just to be safe, on Mac and Linux you might say pip 3
0:43 to ensure that you're installing this into Python 3.
0:47 It looks like we've got it installed, there was some kind of update or something
0:50 but we now have cookiecutter,
0:53 so if we go over here to the pylons organization
0:58 which has pyramid as a subset of it,
1:02 you can see there is a number of cookiecutter templates if you browse around;
1:05 the one we're going to use is this pyramid cookiecutter starter,
1:09 this is the certain most basic, most foundational version,
1:13 it doesn't pull in a whole bunch of different things
1:16 like other specific database integrations and so on,
1:19 because we're going to do that manually and exactly the way we want to do it.
1:23 So we're going to run this template, and all we need to do that
1:25 is get this url to the github page, you know it's a cookiecutter template
1:31 because you have cookiecutter.json.
1:34 Now cookiecutter can install all sorts of things
1:37 not just this, it can create templates and generate them for all sorts of things
1:41 but it's going to work really well for this.
1:44 So we're going to come over here and make sure we're in
1:47 desktop this project area thing, and notice it's empty right now
1:51 so we're going to say cookiecutter and give it this,
1:55 I've already downloaded this one, so it's going to say
1:58 can we get a new copy, yes is a good answer,
2:01 but this is typically how you'll see it here,
2:04 it will ask you a question and say what do you want to call the project
2:06 let's just call it my web app, and then it's going to propose a repo name,
2:12 and a repo name is maybe not the best nomenclature here,
2:15 really this is the actual folder structure for the Python pyramid project
2:22 and this is going to be the Python package name that it's going to use,
2:26 so you have to avoid certain things like test,
2:28 anything that's basically a built in package in Python right,
2:32 like os wouldn't be good, other things you might use, requests wouldn't be good,
2:36 so just be aware of it when you pick this.
2:39 And then, we're going to pick Chameleon for this course
2:42 the JInja 2 probably is the most popular which is why it's a default
2:46 but Chameleon is a much cleaner syntax in my opinion,
2:50 much better language for the web, so we're going with that.
2:54 there's a bunch of stuff, it says okay we've created the project
2:57 now if we look here, you can see there's folder that contains stuff
3:02 that has to do with packaging, so the changes, the and so on,
3:07 and then here we have our actual web projects
3:11 we've got our static files, our templates, our tests, our views and so on,
3:15 so it gives us a little idea of what we could do,
3:18 we could come over here and we could cd into our folder that is created
3:22 the my web app, and then it proposed
3:24 we make a virtual environment so let's go do those things.
3:27 So we'll cd in here, and then we're going to make
3:31 a virtual environment slightly differently than they propose,
3:34 but we're going to say Python 3-m for module, so run the venv module,
3:38 we're going to add a --copies, the reason is on Mac,
3:42 I don't believe this is a problem on the Windows or in Linux
3:45 but on Mac, the way PyCharm interacts with the virtual environments
3:49 if you don't do the copies, it doesn't resolve the symbolic links correctly
3:54 so you want a --copies and we'll call it .env.
3:57 They proposed just env, but if you used .env,
3:59 PyCharm will automatically detect and use this
4:02 so it will save you one step along the way.
4:04 Okay, so we run this, now if we ask which Python
4:09 you see it's the system one, so we have to activate that virtual environment
4:13 so we'll say either source or .env, activate
4:18 notice that my prompt changes and it has a .env on it, that's great,
4:23 if you are on Windows this is slightly different
4:26 you drop the little dot, you don't need that
4:29 and then this is scripts not bin, and this is activate.
4:32 So we have our new prompt, and now if we ask that which Python
4:36 of course we're using the proper one, so let's say pip list, see what we got
4:39 and let's go and upgrade setup tools, this is not technically necessary
4:43 but it's really out of date— it's like eight full versions out of date
4:50 so we're going to do that, and now we have our files here
4:54 we could go and pip install some more stuff
4:57 but we're just going to run this setup file which is going to install
4:59 everything else that we need, so we'll say python
5:02 and if we want to say use this folder structure right here,
5:07 these files right here as the package files,
5:10 don't copy them somewhere else, don't create a distribution or anything like that
5:13 so we're going to say develop, which means reference the files in my working folder,
5:17 that's exactly what we want, we're going to make changes
5:20 we just want to rerun it and see them take.
5:23 Everything is looking good, we finished processing
5:27 the dependencies for our web app, let's do a pip list again,
5:30 notice we have all of our dependencies and their transitive closures
5:35 as well as our app referencing
5:38 straight out of this location that we want to work from.
5:40 Okay, so everything is ready to go, we've got our package registered
5:44 the last thing we want to do is just run it, so we're going to run p.serve
5:48 and we are going to say development.ini,
5:51 so pserve is the way to run the web server and
5:53 then we have to give it a configuration file development or production,
5:57 we want development, because we're not in production, we're in development, let's go.
6:01 Ta-da, look at that, let's open this in our browser and see what we've made,
6:08 and there you have it, there's the pyramid starter project
6:11 and it says welcome to my web app,
6:14 pyramid application generated by cookiecutter;
6:18 so now we have our project, it's ready to go.
6:21 What's next— well we start adding features
6:23 and make this our web app, not just a scaffold.