Episode: 2288
Title: HPR2288: Installing and using virtualenvwrapper for python
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2288/hpr2288.mp3
Transcribed: 2025-10-19 00:54:25

---

This is HBR episode 2,288 entitled, Installing and Using Virtue Nail Rapper for Python.
It is posted by first time post-knocks and is about 11 minutes long and can remain an explicit flag.
The summary is, Installing and Using Virtue Nail Rapper for Python, what I learned in a hard way.
This episode of HBR is brought to you by an honesthost.com.
With 15% discount on all shared hosting with the offer code HBR15, that's HBR15.
Better web hosting that's honest and fair at An Honesthost.com.
Hello Hacker Public Radio. This is Nox.
I'm very excited to be bringing my first show to Hacker Public Radio.
I finally found something that I felt like is worth sharing with the community.
I personally really like Python and I haven't had as much time to work with it lately, but I finally have had the time to get back in.
As I've been learning, I see everywhere people talking about how you should use virtual environments to be able to keep your project separated.
And I've been starting to work with Django, which by the way, if anybody out there would like to do some Django shows, I'm trying to learn and would appreciate that.
And some other little more complex stuff where the virtual environment just really does make sense for me to be using.
So if you're not familiar with what Python's virtual environment is, you set up a virtual environment because in Python you download packages
and they add functionality to your Python, but not all of these packages play nicely with each other.
Some of them require older versions of other packages. They have dependencies.
And so if you download a package that requires an older version of something that you already have installed, it may try to uninstall the current version and put in the old version, or you may end up with the old version and the new version.
And in either case, you're going to run into problems when you go back and try to run your older project later.
It's going to tell you that things are not set up correctly, and then you may have to completely set up your development environment all over again.
And none of us want to do that over and over again. So the answer is virtual environments.
What this does is it sets up a kind of a little, I guess you'd say a DMZ for your packets that you're downloading or packages that you're downloading.
And that way all of your packages are isolated. They're encapsulated, if you will, from all the other ones.
So you enter your virtual environment, and there will be a parentheses and the project name at the beginning of your command line and the terminal that will say project name and then your standard terminal cursor.
And while you're inside that virtual environment, you can download any packages that you need to download.
And then when you leave that virtual environment, then you are back to just the base packages that you've installed and your Python.
So it's very nice. You can even copy them. If you know how to use pip properly, you can do the, what is the name of that file?
You can do the command of freeze, pip freeze, and you can pipe that out to a text file and it'll give, it'll come out with usually people name it requirements.text.
And then you're able to kind of duplicate that environment over and over again.
So let me tell you how to set this up. If you've never done it before, I had to struggle with it.
I kept trying to set it up and I kept messing up. I couldn't understand it.
And so I'm hoping that maybe this description will help people to not have to struggle nearly as hardly as I did to be able to get it all set up.
So the first thing you're going to want to do, and I am assuming here that you already have, you're using Linux, some flavor, and that you are in the Ubuntu or Mint family, you're going to be using, I'm using those.
And so I'm assuming you've got pip. Now the first thing you're going to have to do is you have to install virtual ENV, and I will post here in the notes of these steps that I'm about to go through.
So I use the command sudo with the hflag, the capital hflag, pip install virtual ENV.
Now if one of you guys can tell me why I always need to have the hflag on my sudo when I install these packages, please tell me.
Because if I don't use the hflag, I always get some kind of error saying that I can't get to a certain folder, and it doesn't quite install right.
And I found that when I use the hflag, it works correctly, and I still don't know why, and I would love to know why it works correctly when I do that.
So once you have installed virtual ENV, that is, again, sudo with the capital hflag, pip install virtual environment, then you're ready to install what I found is an excellent addition, and it is called virtual ENV wrapper.
Now the virtual ENV wrapper will make all of the commands much easier to get in and out of your virtual environment.
So to install the virtual ENV wrapper, you want to do sudo, again, capital hflag, pip install virtual ENV wrapper.
Now what this does is this gives you some simple commands to be able to get in and out of your virtual environment.
Without the virtual ENV wrapper, I found it tedious and cumbersome to have to really move around folders and have to, the commands they want you to use are harder to remember and don't make as much sense.
The virtual ENV wrapper gives you the tools we'll get to those here in a second.
Now for this to work all the time, the other thing I figured out is I would install virtual ENV wrapper, and then I would go to use the commands and they wouldn't work.
And what I found is you've got to modify your .bashrc file and add a couple of lines to it so that when you open bash they're available.
And I did the first time I installed it, but for some reason they weren't staying persistent.
So again, if someone can, I'm learning all this stuff too, along with everybody, we're always learning stuff.
If someone can explain to me why those commands weren't staying persistent and why I had to put them in the bashrc, or maybe that's just the way it has to be done, I don't know.
But once I added these two lines to it and they are export, work underscore home equals and then the tilde slash capital ENVS.
And I also have these down in the notes so that you can see them. So we have to export that and then there's a source user local bin virtual ENV wrapper.sh and that one is also down in the notes.
So you add those two lines to your bashrc file and then all these commands that we're talking about are going to work properly.
So here are the commands to create. Once you've installed virtual ENV and once you've installed virtual ENV wrapper, now you're ready to start creating a virtual environment.
So the first command we're going to talk about is MK virtual ENV. So that is how you make a project. So all you have to do is be in whatever folder you want to create the project in.
Once you've navigated to that folder, you type MK virtual ENV and then the name of the project that you want to start and hit enter. And what that does is as soon as you hit enter, it will create what we said earlier, that kind of DMZ isolated environment for you to have to set up your project.
And then once you make it, you'll have to actually enter into it. I don't believe it actually puts you in the environment after you type make. Then after you've made this environment, the command to actually get in it is wonderful.
It is work on, just one word work on. And when you type work on and then your project name, it will automatically launch you into the virtual environment.
And like I said, you'll know you're in the virtual environment because at the front of your command line in parentheses will be the name of your project name. So you'll know that you're working inside that project.
And now you can begin to use pip to install packages just inside that virtual environment. And let me point out here, I also had to learn the hard way that now you don't need to use sudo at all.
If you use sudo pip inside a virtual environment, it will try to install it back in the base Python install for lack of a better way of describing it.
And then when you go to run your code, your script, it'll say that it doesn't have the package. And then you'll do a pip list. And when pip lists the packages, it won't be there.
So the only way that you're going to be able to install them in your virtual environment is just to use pip. So pip install whatever package you want. And you're good to go.
The next command that you're going to want to know is RM virtual environment, which is remove virtual ENV.
So if you are done with a project and you don't want it anymore, that's all you have to type. Once you are outside of the project, you type RM virtual ENV and it's going to remove that project completely.
So make sure that you don't need it anymore. If you want to list all the virtual environments you've created, because I know that happens to me, I've created a virtual environment, I work on it, and I come back to next day.
And I think, did I create that with an underscore, did I use a dash, did I, I don't remember.
So if you type in LS virtual ENV, it will list all the current virtual environments that it has, that it's aware of.
So like I said, if you want to get into your project name, type work on and the project name, and you're in. And when you're done, the command to leave that virtual environment is deactivate.
How easy is that? You just type deactivate and bang, you leave the virtual environment and you're back to your regular command line and back into your regular Python setup.
So I hope this has been helpful for you. I know I had to struggle to figure out these little tidbits that I've thrown in here, and I don't know why when I looked around the web, I just couldn't find all of this information in one location.
I will include my notes here in the show along with it. I want to say again, just a big thank you to everybody in the hacker public radio community.
I've been listening for about a year and I'm just loving it and I'm so excited that I finally thought of a show that I thought would be a help to the community and I hope that it has been.
Thank you all.
You've been listening to Hacker Public Radio at HackerPublicRadio.org. We are a community podcast network that releases shows every weekday, Monday through Friday.
Today's show, like all our shows, was contributed by an HBR listener like yourself. If you ever thought of recording a podcast, then click on our contributing to find out how easy it really is.
HackerPublic Radio was founded by the Digital Dove Pound and the Infonomicon Computer Club and is part of the binary revolution at binrev.com.
If you have comments on today's show, please email the host directly, leave a comment on the website or record a follow-up episode yourself.
Unless otherwise status, today's show is released under Creative Commons, Attribution, ShareLive, 3.0 license.
