When we install a package from Py PI using the copy of pip that's created by the virtualenv tool, it will install the package into the site-packages directory inside the virtualenv directory. We only need the virtualenv tool itself when we want to create a new environment. Start by changing directory into the root of our project directory, and then use the virtualenv command-line tool to create a new environment: Here, env is just the name of the directory we want to create our virtual environment inside.It's a common convention to call this directory env, and to put it inside our project directory (so, say we keep our code at ~/myproject/, the environment will be at ~/myproject/env/ - each project gets its own env). If we look inside the env directory we just created, we'll see a few subdirectories: The one we care about the most is bin.If you create a table without quotes around the name, for example CREATE My Table..., the resulting table name will be converted to upper case (i.e.MYTABLE) and will be treated in a case insensitive manner.Now, instead of typing python to get a Python shell, we type env/bin/python: Instead of typing env/bin/python and env/bin/pip every time, we can run a script to activate the environment.This script, which can be executed with source env/bin/activate, simply adjusts a few variables in our shell (temporarily) so that when we type python, we actually get the Python binary inside the virtualenv instead of the global one: So, now we can just run pip install requests (instead of env/bin/pip install requests) and pip will install the library into the environment, instead of globally.A similar example is why do the default Oracle databases use a Western European character set when UTF is required for global applications that use non ASCII characters? A Virtual Environment enables us to keep the dependencies required by different projects in separate places, by creating virtual Python environments.
Test Case class Simple tool - Google page ranking by keywords Google App Hello World Google App webapp2 and WSGI Uploading Google App Hello World Python 2 vs Python 3 virtualenv and virtualenvwrapper Uploading a big file to AWS S3 using boto module Scheduled stopping and starting an AWS instance Cloudera CDH5 - Scheduled stopping and starting services Removing Cloud Files - Rackspace API with curl and subprocess Checking if a process is running/hanging and stop/run a scheduled task on Windows Apache Spark 1.3 with Py Spark (Spark Python API) Shell Apache Spark 1.2 Streaming bottle 0.12.7 - Fast and simple WSGI-micro framework for small web-applications ...
To install it: Note that we haven't installed virtualenvwrapper.sh, this may not work yet.
As initialization steps, we will want to add the command to source /usr/local/bin/to our shell startup file, changing the path to depending on where it was installed by pip: virtualenvwrapper.user_scripts creating /home/k/Envs/premkproject virtualenvwrapper.user_scripts creating /home/k/Envs/postmkproject virtualenvwrapper.user_scripts creating /home/k/Envs/initialize virtualenvwrapper.user_scripts creating /home/k/Envs/premkvirtualenv virtualenvwrapper.user_scripts creating /home/k/Envs/postmkvirtualenv virtualenvwrapper.user_scripts creating /home/k/Envs/prermvirtualenv virtualenvwrapper.user_scripts creating /home/k/Envs/postrmvirtualenv virtualenvwrapper.user_scripts creating /home/k/Envs/predeactivate virtualenvwrapper.user_scripts creating /home/k/Envs/postdeactivate virtualenvwrapper.user_scripts creating /home/k/Envs/preactivate virtualenvwrapper.user_scripts creating /home/k/Envs/postactivate virtualenvwrapper.user_scripts creating /home/k/Envs/get_env_details New python executable in /home/k/Envs/env1/bin/python Installing setuptools, pip, wheel..
The adjustments to our shell only last for as long as the terminal is open, so we'll need to remember to rerun source env/bin/activate each time you close and open our terminal window.
If we switch to work on a different project (with its own environment), we can run deactivate to stop using one environment, and then source env/bin/activate to activate the other.