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 and if we ask things like, which Python? We have our virtual environment listed or active
0:07 and we do a pip list, you can see all the stuff we like client's list and httpie uWSGI are all set up and ready to go.
0:14 However, if we log out and we log back into the server we ask the same question, which Python ugh, well, it's not the same one.
0:24 There's a cool little trick that we can do to help us always have the right environment active. When you log into the server, what is the chances
0:32 that you want to change the system Python? Pretty low. Or the chances you might want to upgrade your requirements for your web app
0:40 or install some other packages it's going to need very high. So on this server we're going to actually set it up
0:47 so that when we log in, it automatically activates that virtual environment. So let's see where it went. It was over here in venv/bin/activate
0:57 that's the one so what we can do to make that happen it's super easy. We're going to edit our .zshrc, with Bash
1:06 then that would be .bashrc. Down here at the bottom we're just going to tell it to source that command okay?
1:12 That'll effectively activate it right when we log in before we even do anything so let's log out log back in. Tada!
1:20 There it is, and we ask which Python or pip list. We're all good to go so that's a nice little trick technique that you can add
1:27 to make sure we're always focused on our web app and not messing with the server. Of course, you can deactivate. Deactivate
1:35 if you need to and get back to, like, the system Python. But, honestly, you almost never need to do that.
1:40 So this activate virtual environment and login nice and handy.


Talk Python's Mastodon Michael Kennedy's Mastodon