Building data-driven web apps with Flask and SQLAlchemy Transcripts
Chapter: Deployment
Lecture: Make the virtual environment always active

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Here we are in our server
0:01 and if we ask things like, which Python?
0:03 We have our virtual environment listed or active
0:06 and we do a pip list, you can see all the stuff we like
0:08 client's list and httpie
0:11 uWSGI are all set up and ready to go.
0:13 However, if we log out and we log back into the server
0:18 we ask the same question, which python
0:19 ugh, well, it's not the same one.
0:23 There's a cool little trick that we can do
0:25 to help us always have the right environment active.
0:28 When you log into the server, what is the chances
0:31 that you want to change the system Python?
0:33 Pretty low. Or the chances you might want
0:36 to upgrade your requirements for your web app
0:39 or install some other packages it's going to need
0:42 very high. So on this server
0:44 we're going to actually set it up
0:46 so that when we log in, it automatically activates
0:49 that virtual environment.
0:51 So let's see where it went.
0:53 It was over here in venv/bin/activate
0:56 that's the one
0:58 so what we can do to make that happen
0:59 it's super easy.
1:00 We're going to edit our .zshrc, with Bash
1:05 then that would be .bashrc. Down here at the bottom
1:07 we're just going to tell it to source
1:09 that command okay?
1:11 That'll effectively activate it right when we log in
1:14 before we even do anything so let's log out
1:17 log back in. Tada!
1:19 There it is, and we ask which Python or pip list.
1:22 We're all good to go
1:23 so that's a nice little trick
1:25 technique that you can add
1:26 to make sure we're always focused on our web app
1:28 and not messing with the server.
1:30 Of course, you can deactivate. Deactivate
1:34 if you need to and get back to, like, the system Python.
1:37 But, honestly, you almost never need to do that.
1:39 So this activate virtual environment and login
1:42 nice and handy.