Virtual python environments and you: A developer's primer
by Jason Kennedy ● November 6th, 2015
Tags:
getting started
python
environments
One of the first things you should do before you start playing with stackrc files and api’s with OpenStack is get your computer ready to do the development work. What this normally means is installing some client-side tools that let us interact with our OpenStack environments remotely.
The trouble is, it’s extremely easy to mess up your machine by installing things the wrong way. Sometimes it’s necessary to run different tools or even different versions of the same tooling (OpenStack is fun!). For these things, you should be working in virtual environments.
I have written previously about installing python-novaclient in OS X; today I’ll install python-openstackclient in a python virtual environment that I create using vex.
Vex is actually a wrapper around virtualenv, making that tool simpler to use. I prefer vex because you can run one-off commands to specific environments without having to actually enter said environments; as it says, making the tools simpler to use. Let me show you:
This is what you should see after it’s set up:
Now, you have a decision to make. You should have the openrc/stackrc file from your environment (you get it from Horizon). You can either source it outside the virtual environment, or within. If you source it outside, you’ll be able to run one-off commands, which I’ll show you below. If you source it inside, you’ll need to work from within the virtual environment so you can interact with your cloud. Either way is fine.
You’re all but done. All you need to do now is create a virtual environment for yourself to install your dev tools into.
Note you’re in a different bash shell. Once inside, just install the tool that you want (in our case, we’ll use python-openstackclient):
From here, it should be smooth sailing:
To get out of the virtual environment shell, simply type exit. To see what current virtual environments you have running, type:
and to get back into an existing environment:
The best part of using vex, though, is the simplicity. From your standard terminal prompt, you can interact directly with any of the python virtual environments you’ve created without having to jump into them:
That’s it! bear in mind you can create endless vex and nest sessions, which eventually will stop the world from spinning, flinging us all into space*, so I don’t recommend it.