Changes

Jump to: navigation, search

OPS435 Python Lab 1

170 bytes added, 13:14, 1 August 2017
Creating the introductory "Hello World" Script
:'''Perform the following steps:'''
:#The first step is to update your entire system. <sourcelang="bash">
yum update
</source>
:#Install extra packages for enterprise linux:<sourcelang="bash">
yum install epel-release
</source>
:#Next install applications that we required, first Python version 3 and version 2:<sourcelang="bash">
yum install python34 python34-devel # Install python3.4 and python3.4 development libraries
yum install python python2-devel # Install python2.7 and python2.7 development libraries
</source>
:#Next, you will install a couple of useful applications called '''tmux''' and '''screen'''. They are referred to as '''terminal multiplexers'''. If you plan to spend a lot of time in the terminal, this powerful tool will help you get it done. Lets install it and plan to use it later:<sourcelang="bash">
yum install screen tmux && ln -s /usr/bin/true /etc/sysconfig/bash-prompt-screen
</source>
:# Set your hostname to the Linux Distribution we are using in case you did not set it correctly during the install process:<sourcelang="bash">
hostnamectl set-hostname centos7 # Set your hostname to distribution-name
</source>
'''Sublime'''<br>Another powerful and popular text editor designed for programming. Is not free or open source.}}</blockquote>
<ol><li value=6" style="margin-left:25px;">'''Python pip''' is a package manager specifically for Python. While it is usually not recommended to install software outside of '''dnf''' or '''yum''', sometimes the only way to get a specific or latest version will be through pip:<sourcelang="bash">
yum install python-pip # Install python2.7 pip
yum install python34-pip # Install python3.4 pip
</source></li>
<li style="margin-left:25px;">Issue the following command to install '''git''':<sourcelang="bash">
yum install git # Install git command line tool
</source></li></ol>
<blockquote style="margin-left:35px;">{{Admon/tip|What is a Git?| '''Git''' refers to a '''version control system''' that allows you to track any changes made to files and programs. Our primary use for git in this course will be for backup onto to the internet. Check out '''bitbucket''' for a free private code repository.}}</blockquote>
<ol><li value="8" style="margin-left:25px;">IPython will be one of the tools we will use the most. Lets install it. You will learn more about it in the next section:<sourcelang="bash">
yum install python-ipython # Install ipython for python2.7
pip3.4 install ipython # Install ipython for python3.4
</source></li>
<li style="margin-left:25px;">Issue the following commands in your shell to check your work for this section:<sourcelang="bash">
cd ~/ops435/lab1/
pwd #confirm that you are in the right directory
<li style="margin-left:25px;">
Perform the following steps to evaluate this unit. Run these check scripts regularly as you work through the labs, they may give you hints if you get stuck.</li>
:<sourcelang="bash">
cd ~/ops435/lab1/
pwd #confirm that you are in the right directory
:'''Perform the following steps:'''
:# Using a text editor, open a new text file called '''lab1a.py''':<sourcelang="bash">
vim ~/ops435/lab1/lab1a.py
</source>
:#Write the following code into our python file. Note the she-bang line at the top of the file to run this script in the python3 environment. You will need to add this she-bang line for all python scripts you create for this course.<sourcelang="python">
#!/usr/bin/env python3
</source>
:#Now, from the Bash shell we will give it the correct Linux permissions in order to run your newly-created python script. This is just showing the multiple ways you can use this python script. You are not required to have IPython running on a system, however hopefully we can use IPython's powerful features to our advantage.
:# Run your python script by issuing the following commands:<sourcelang="bash">
chmod 755 ~/ops435/lab1/lab1a.py
python3 ~/ops435/lab1/lab1a.py
</source>
:#Download the check script and check your work. Enter the following commands from the bash shell.<sourcelang="bash">
cd ~/ops435/lab1/
pwd #confirm that you are in the right directory

Navigation menu