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

Talk Python's Mastodon Michael Kennedy's Mastodon