Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Python Scripting for System Administrators

You're reading from   Mastering Python Scripting for System Administrators Write scripts and automate them for real-world administration tasks using Python

Arrow left icon
Product type Paperback
Published in Jan 2019
Publisher Packt
ISBN-13 9781789133226
Length 318 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Ganesh Sanjiv Naik Ganesh Sanjiv Naik
Author Profile Icon Ganesh Sanjiv Naik
Ganesh Sanjiv Naik
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Preface 1. Python Scripting Overview FREE CHAPTER 2. Debugging and Profiling Python Scripts 3. Unit Testing - Introduction to the Unit Testing Framework 4. Automating Regular Administrative Activities 5. Handling Files, Directories, and Data 6. File Archiving, Encrypting, and Decrypting 7. Text Processing and Regular Expressions 8. Documentation and Reporting 9. Working with Various Files 10. Basic Networking - Socket Programming 11. Handling Emails Using Python Scripting 12. Remote Monitoring of Hosts Over Telnet and SSH 13. Building Graphical User Interfaces 14. Working with Apache and Other Log Files 15. SOAP and REST API Communication 16. Web Scraping - Extracting Useful Data from Websites 17. Statistics Gathering and Reporting 18. MySQL and SQLite Database Administrations 19. Assessments 20. Other Books You May Enjoy

Python installation

In this section, we will be learning about the installation of Python on different platforms, such as Linux and Windows.

Installation on the Linux platform

Most Linux distributions have Python 2 in their default installations. Some of them also have Python 3 included.

To install python3 on Debian-based Linux, run the following command in the Terminal:

sudo apt install python3

To install python3 on centos, run the following command in the Terminal:

sudo yum install python3

If you are unable to install Python using the preceding commands, download Python from https://www.python.org/downloads/ and follow the instructions.

Installation on the Windows platform

For installing Python in Microsoft Windows, you'll have to download the executable from python.org and install it. Download python.exe from https://www.python.org/downloads/ and choose the Python version that you want install on your PC. Then, double-click on the downloaded exe and install Python. On the installation wizard, there's checkbox that says Add Python to the path. Check this checkbox and then follow the instructions to install python3.

Installing and using pip to install packages

In Linux, install pip as follows:

sudo apt install python-pip --- This will install pip for python 2.
sudo apt install python3-pip --- This will install pip for python 3.

In Windows, install pip as follows:

python -m pip install pip

Installation on Mac

To install python3, first we must have brew installed on our system. To install brew on your system, run the following command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

By running the preceding command. brew will get installed. Now we will install python3 using brew:

brew install python3

Installing Jupyter notebook

For installing the Jupyter Notebook, download Anaconda.

Install the downloaded version of Anaconda and follow the instructions on the wizard.

Install Jupyter using pip:

pip install jupyter

In Linux, pip install jupyter will install Jupyter for python 2. If you want to install jupyter for python 3, run the following command:

pip3 install jupyter

Installing and using the virtual environment

Now we will see how to install the virtual environment and how to activate it.

To install the virtual environment on Linux, perform the following steps:

  1. First check whether pip is installed or not. We are going to install pip for python3:
sudo apt install python3-pip
  1. Install the virtual environment using pip3:
sudo pip3 install virtualenv
  1. Now we will create the virtual environment. You can give it any name; I have called it pythonenv:
virtualenv pythonenv
  1. Activate your virtual environment:
source venv/bin/activate
  1. After your work is done, you can deactivate virtualenv by using following command:
deactivate

In Windows, run the pip install virtualenv command to install the virtual environment. The steps for installing virtualenv are same as with Linux.

Installing Geany and PyCharm

You have been reading a chapter from
Mastering Python Scripting for System Administrators
Published in: Jan 2019
Publisher: Packt
ISBN-13: 9781789133226
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime