(This post is part of the finding-odin series.)
Read the introduction: Finding my cat Odin using Python and Elasticsearch.
We will first install the Python components we will need to create our pet finding search engine.
Objective: Install Python3.5.2 and virtualenv.
I develop in an Ubuntu 14.04 VM. I unfortunately do not have time to explain the process of creating an Ubuntu VM. Please search for tutorials on installing Ubuntu 14.04 via Vagrant for your operating system.
Since I will use Python3 for developing this project, let's cover the installation process.
Download and untar the Python 3.5.2 source tarball
$ wget "https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz" $ tar -xf Python-3.5.2.tgz $ cd Python-3.5.2
Install the Python3 headers
$ sudo apt-get install python3-dev
(Optionally) install readline for useful tools like ptpython
$ sudo apt-get install libreadline6 libreadline6-dev
Compile and install from source. By using
altinstall, we ensure we don't
override the currently installed system Python. In other words, we have to
python3.5 instead of just
python to use this Python version.
Once we set up our virtual environments that will not be an issue.
$ ./configure $ make $ sudo make altinstall
Afterward, verify the Python version is correct.
$ python3.5 --version Python 3.5.2
Now we install setuptools so we can get access to pip, the Python package manager.
$ wget https://bootstrap.pypa.io/ez_setup.py $ sudo python3.5 ez_setup.py
The command above installed a tool called
easy_install. We will use
easy_install to install pip. pip is a superior python package manager, but we
have to use easy_install to initially download pip since easy_install ships
directly with Python.
$ sudo easy_install pip
Now we use pip to install virtualenv, the tool for managing virtual environments. Virtual environments allow you to use isolate library installations to a specific project. This allows us to have specific library versions associated with specific projects, protecting us from breaking changes when we upgrade a library that may break backwards compatibility with a previous version.
$ sudo pip install virtualenv
Installing a virtualenv
Create a directory called
.envs in the home directory. We will store
virtualenvs here. cd to the directory after you create it.
$ mkdir ~/.envs $ cd ~/.envs
Create a virtualenv called
austinpetfinder. We will instruct this virtual
environment to use our recently installed Python3.5.2.
~/.envs$ virtualenv --python=python3.5 austinpetfinder
We just created the virtual environment, but to use it we must "activate" it. We activate the virtualenv using the following command:
$ source ~/.envs/austinpetfinder/bin/activate
Afterwards, you should see
(austinpetfinder) prepended to the shell prompt.
Now verify the python version within the virtualenv is Python 3.5.2.
(austinpetfinder)$ python --version Python 3.5.2
When you are finished working with a virtualenv (perhaps you want to switch
virtualenvs), run the
deactivate command. You will see the virtualenv name
disappear from the shell prompt.
(austinpetfinder)$ deactivate $ # your next command
We now have Python3.5.2 installed as well as the virtual environment manager virtualenv and the Python package manager pip.
Next we will create a "hello-world" boilerplate application that will establish the structure and convention of our pet finding search engine.