IDLE in a Virtual Environment3:23 with Kenneth Love
Using tools like IDLE in a virtualenv isn't as straightforward as it should be. I'll show you how to launch it so your custom project packages are available and how to use a requirements file to quickly build up an environment.
You can always get a list of installed packages with
pip freeze. If you're in a virtualenv, you'll get the virtualenv's list of packages. If you're not, you'll get a list of your global packages.
pip freeze > requirements.txt is the fast way to generate your requirements file the first time.
Requirements files always have the same layout:
package_name==1.2.3. You can also use
>=, too (e.g.
Django>=1.9,<2.0 would select the latest version of Django that's newer than, or equal to, 1.9 and less than 2.0).
Now, if you're going to use Idle and you're going to use virtualenv, 0:00 I need to show you a special thing for launching Idle inside of your virtualenv. 0:03 Normally, launching Idle would not let you use your virtualenv installed packages. 0:09 But if we launch Idle from inside of our virtualenv, 0:14 python -m idlelib, then we have access to our libraries. 0:19 Like here I can say import flasks, no problems. 0:26 So if your virtualenv gets screwed up and you need to start over, what do you do? 0:30 I said in the last video that they're disposable, right? 0:35 We deleted it, we made it again, and I mentioned installing packages. 0:38 So first of all, let's see what we have installed. 0:43 So we'll do pip freeze and we have flask, it's dangerous, 0:45 Jinja2,MarkupSafe and Werkzeug. 0:50 Which I apologize to all of my German speaking students. 0:53 I know I said that wrong. 0:57 If you can send me a better pronunciation of it, I would love it. 0:58 This givesa list of all the packages that we have installed and then we have this 1:01 double equals and the exact version of the package that we have installed, 1:06 so we have exactly Flask 0.10.1, not 0.10.2 or 0.10.0. 1:12 So we can copy this. 1:18 Alright, we can [SOUND] copy that. 1:21 Or we can be lazy. 1:23 We copy it, we paste it into a new file, right? 1:25 Or we can be lazy and let the computer do it for us. 1:27 So if we do pip freeze and then we do a greater than sign and 1:31 then the name of a file, which we're gonna do requirements.txt. 1:34 And now if I cat, 1:40 requirements requirements.txt which cat just makes it print. 1:42 It's got the same thing in there, so the greater than tells the computer to put 1:44 the output of pip freeze into a file named requirements.txt. 1:49 Now this file name isn't a requirement, but it is a very common practice to use 1:53 that name and some third parties services like Kiroku kind of expect that name. 1:58 Okay, so let's make sure this works. 2:03 So I should be able to get out of here, deactivate and 2:06 I should be able to rm -rf fb. 2:10 So I do not have fb installed. 2:13 And then, I should be able to make a new one. 2:16 So let's go up here, let's find my thing I did, there it is, python3 -m venv fb. 2:20 Alright and then, source fb/bin/activate. 2:27 Okay, we are back to this. 2:33 And if we do pip freeze, there is nothing installed yet 2:34 because I haven't installed things yet. 2:37 Let's install things. 2:39 So we can do pip install, and normally here we would type in like, flask, right? 2:40 Let's not do that, though. 2:46 -r says "Hey, go read this file". 2:47 And we're gonna read requirements.txt. 2:51 So press enter, and it installs everything. 2:54 And if we now do pip freeze, there is our normal list of all of our stuff. 2:58 Everything's installed again, that's awesome. 3:03 Congratulations, you have a solid local Python installation you can use to follow 3:07 along with the courses here on Treehouse or just for experimenting with code, or 3:12 writing software for clients of your own, or a developer job. 3:16 I'm sure you'll do so much with these new tools. 3:20
You need to sign up for Treehouse in order to download course files.Sign up