A Not Real Place


The other night, I made another step in the journey to learning python, virtualenv has been achieved! Virtualenv is a python version of VMWare or VirtualBox. It allows you to create a virtual environment on your local machine or server and not have to worry about interfering with your base configuration.

For reference, I installed 15.0.3, the stable version at the time of writing. Install went very smoothly, and was over very quickly. Then came the part of learning how to use it. This is how I set mine up… Since I am using a Mac, I opened a new Terminal window. I went to my home folder, so the prompt looks like this –

machine_name:~ user_name$

I am using the placeholder “home_folder” to represent yours, as I am sure its actual name is different than mine. Once there, I created a new folder called python-env. I then changed directory into the new folder, so my prompt looks like this (your prompt may look different based on your settings)-

machine_name:python-env user_name$

I typed in this command,

virtualenv new_env

“new_env” is the name of the new environment you want to create. Which, by default, is python 2.x. This will become the root folder for your project. If you have python 3 installed on your system, and you would prefer to use that to create an environment, type this instead-

virtualenv -p python3 new_env

-As a side note, if you want to run a virtualenv on a mac and need to import matplotlib, per this post, use the following command instead… (I had an issue, and this worked for me)

python -m venv my-virtualenv

Now change directory into the new_env.

machine_name:new_env user_name$

This is the part that threw me for a little bit. type in the following command… You actually type in the word “source”. I was making assumptions that it was intended as a variable name. Nope, just type it in!

source bin/activate

You will now be in the new virtual environment, and your prompt will look like this-

(new_env)machine_name:new_env user_name$

The appearance of the parenthesis at the beginning with the environment name indicates that is has been activated. To quit the environment, type-

deactivate

Tada!!! There you have it! You know have a way of creating and using virtual environments to play with to your hearts content. I will not be looking into virtualenvwrapper at this time. This package is a set of extensions that “…include wrappers for creating and deleting virtual environments and otherwise managing your development workflow.” Keep in mind, this is an example of how I was able to install my virtualenv, I am not experienced enough to give best practice advice. I will say, when installing dependencies, do so to the local environment, not globally. That would defeat the purpose of the virtual environment separation. This page may provide more direction of how to do this properly.