Learning Python Network Programming

(Sean Pound) #1
Preface

[ ix ]

Though Python 3.4 is the preferred version, all the examples should run on
Python 3.1 or later, except for the following:



  • The asyncio example in Chapter 8, Client and Server Applications, as the
    asyncio module was only included in Version 3.

  • The Flask example in Chapter 9, Applications for the Web, which requires
    Python 3.3 or later


We're also targeting the Linux operating system, and the assumption is made
that you are working on a Linux OS. The examples have been tested on Windows
though, and we'll make a note of where there may be differences in the requirements
or outcomes.


Virtual environments


It is highly recommended that you use Python virtual environments, or "venvs",
when you work with this book, and in fact, when doing any work with Python.
A venv is an isolated copy of the Python executable and associated files, which
provides a separate environment for installing Python modules, independent from
the system Python installation. You can have as many venvs as you need, which
means that you can have multiple module configurations set up, and you can switch
between them easily.


From version 3.3, Python includes a venv module, which provides this functionality.
The documentation and examples are available at https://docs.python.org/3/
using/scripts.html. There is also a standalone tool available for earlier versions,
which can be found at https://virtualenv.pypa.io/en/latest/.


Installing Python 3


Most major Linux distributions come preinstalled with Python 2. When installing
Python 3 on such a system, it is important to note that we're not replacing the
installation of Python 2. Many distributions use Python 2 for core system operations,
and these will be tuned for the major version of the system Python. Replacing the
system Python can have severe consequences for the running of the OS. Instead,
when we install Python 3, it is installed side by side with Python 2. After installing
Python 3, it is invoked using the python3.x executable, where x is replaced with the
corresponding installed minor version. Most packages also provide a symlink to this
executable called python3, which can be run instead.

Free download pdf