[go: up one dir, main page]

0% found this document useful (0 votes)
8 views10 pages

Lec 5

This tutorial covers the installation and initial setup of Ubuntu 14.04 and how to use the terminal to run Python. It explains how to verify internet connectivity, update package lists, and install Python and pip for package management. The tutorial concludes with a simple example of sending a GET request using the requests library in Python and creating a basic 'Hello World' script.

Uploaded by

puppy567567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

Lec 5

This tutorial covers the installation and initial setup of Ubuntu 14.04 and how to use the terminal to run Python. It explains how to verify internet connectivity, update package lists, and install Python and pip for package management. The tutorial concludes with a simple example of sending a GET request using the requests library in Python and creating a basic 'Hello World' script.

Uploaded by

puppy567567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Privacy and Security in Online Social Networks

Department of Computer Science and Engineering


Indian Institute of Technology, Madras

Lecture – 05
Tutorial 1 Part 2 Python

(Refer Slide Time: 00:11)

Hi everyone. In the last video we learnt how to install Linux on our systems. We installed
Ubuntu 14.04 desktop edition in a virtual environment. So, now in this video, we will
start off from where we left in the last part.

In this video, we will learn how to use the terminal, and see how to run python on
Ubuntu. So, after you have completed the installation process of Ubuntu, and restarted
your system, you will reach this login screen. This login screen will have a user account
that you created, and a guest session. So, just put in the password that you created at the
time of installing Ubuntu, and press enter to login. Now, since it is the first time that you
are logging into your new virtual machine, it will take a few seconds before the desktop
loads. So, this is how the Ubuntu desktop looks like.
(Refer Slide Time: 01:06)

You can see a bunch of icons in the left hand side column. They are some applications
that are preinstalled in Ubuntu. So, first, we will see how to reach the terminal. Take the
mouse pointer to the left top, the first icon in the bunch of icons in the left column, and
click on the first icon.

(Refer Slide Time: 01:28)


This will open a search area where you can search for applications, or anything, in your
virtual machine. Now, here type in terminal, and you should see the terminal app.

(Refer Slide Time: 01:35)

Left click on the app to open the terminal.

(Refer Slide Time: 01:42)


The terminal is a command line interface for Ubuntu, and it is very similar to MSDOS
for windows. But, it is very different than MSDOS, in terms of the commands and
functions that it supports, and in many ways, is much more powerful than MSDOS. So,
first, let us verify if the internet is working on this virtual machine. You type ping space
Google dot com, and press enter.

Now, if you see such replies, you know that, the internet is working. Press control c to
stop pinging. If you see some other error messages, like request timed out, or destination
host unreachable, that means that, the internet is not working on this virtual machine.
Please refer to the previous video, to check the settings of this virtual machine, and make
sure that, you have configured the virtual machine in a way that the internet works. Now,
an important thing to do with a fresh installation of Ubuntu is to update the list of
packages that are available for installation on this operating system.

(Refer Slide Time: 02:45)

This can be done by running the sudo apt get update command on the terminal. Now, this
is a system level operation; so, only a super user, or a user with administrative rights, can
execute this command. This is why we add sudo before executing most apt get
commands. Sudo is short for super user do. Now, it will ask you for your account
password. So, apt get is a command line package management tool for Ubuntu, which is
used to install, remove, and manage software packages.

When you type update with apt get, it instructs this package manager to download a list
of all the latest software packages, and their latest available versions, from the internet.
You can see a list of URLs here on the screen, from where the apt get is downloading the
latest list of packages. These URLs are online software repositories, which maintain the
list of latest software packages available for various versions of Ubuntu. Now, we do not
need to go into more details for the purpose of this course; once the apt get update
operation is complete, let us get started with python. Now, python comes preinstalled
with most versions of Ubuntu.

(Refer Slide Time: 03:53)

You can enter the python shell by simply typing in python in the terminal, and pressing
enter. So, we can see here that, python version 2.7.6 is installed. So, before we start
working with python, let us install a package manager for python, so that, we can install
and manage new python packages easily.
(Refer Slide Time: 04:10)

Exit the python shell, and type ‘sudo apt get install python hyphen pip’. Now, this
command instructs the apt get package manager to download and install the package
name python hyphen pip.

(Refer Slide Time: 04:21)


Now, we just updated the list of repositories. So, apt get will install the latest available
version of python pip. So, as you can see here, apt get automatically finds out all the
dependencies for this new package, and gathers a list of all the packages that would need
to be installed, or upgraded, to successfully install python pip. This makes installing and
managing packages extremely convenient.

And, this is one of the prime reasons that we are using Ubuntu. You do not have to worry
about any version mismatches, or any unmet dependencies, or any missing modules,
etcetera. It also tells you the amount of additional disk space that will be used, after the
installation is complete. Now, press y and enter to continue.

(Refer Slide Time: 05:02)

Now, just like apt get is used to install and manage packages for Ubuntu, pip is used to
install and manage packages for python. So, just like we used apt get install to install
packages for Ubuntu, we can use pip install to install packages for python.
(Refer Slide Time: 05:27)

Now, let us try to install a package using pip. Now, similar to apt get, we type sudo pip
install package name; let us say, requests. Now, a request is http library for python. We
will use this package to send get requests to some of the social network APIs in the next
tutorial. So, it looks like, it is already installed here. So, let us just go to the python shell,
and try out this library. Type python in the terminal and press enter. Now, to use any
library, we will have to import it first. So, we write import requests, and press enter. This
is very similar to the hash include statements in C or C++ programming.

Now, let us start by a sending a get request to Google dot com. This is essentially the
same thing that your internet browser does, when you open Google, or any other website,
in your browser. It sends a get request to the website, receives a response, and displays it.
Now, we are doing the same thing in python. So, we write response equal to requests dot
get Google dot com, and press enter. Now, you should type response and press enter; you
see this response object with the code 200. Now, 200 is the http code for an OK
response. It means that, we were successfully able to send the request and get a response.
(Refer Slide Time: 06:50)

Now, to see the text part of this response, we type response dot text, and press enter. This
is the HTML source code of google.com. You get the same response when you open
Google in your browser; but, the browser is capable of understanding this HTML code,
and showing it as a pretty looking web page that you see, OK.

(Refer Slide Time: 07:12)


Let us get out of the python shell, and write a python code in a script, or a file, which you
can reuse; because you cannot program in the shell forever; because, as soon as you exit
the shell you just lose all your code. So, now, let us open a new python script file, and
name, and call it, hello dot py. I will be using the vi editor to write this script, but you
can use any text editor you like. So, let us write the customary hello world program. This
is just very easy; you just type print 'hello world' in the file, and save it.

(Refer Slide Time: 07:35)

To execute the python script, just write python space hello dot py, and press enter, and
there you have it; you have the first hello world program in python. Now, this is all for
this tutorial. This tutorial was just a getting started kit for Ubuntu and python.

In the next tutorial, we learn how to collect data from Facebook, using the graph API. If
you have any questions, or comments, please post them on the NPTEL discussion forum.
We will be happy to assist you with any doubts or clarification or help.

Thanks.

You might also like