Python network programming environment construction
Python Network Programming Environment Setup
Python 3 is available for Windows, Mac OS, and most Linux operating systems. Although Python 2 is available for many other operating systems, Python 3 support is either not available for them or has been abandoned.
Local Environment Setup
Open a terminal window and type “python” to find out if it’s installed and what version it is.
Obtaining Python
Windows Platform
The latest version of Python 3 (Python 3.5.1) can be obtained from this download page
There are different installation options.
- Windows x86-64 embeddable zip file
- Windows x86-64 executable installer
- Windows x86-64 network-based installer
- Windows x86 embeddable zip file
- Windows x86 executable installer
- Windows x86 network-based installer
Note – To install Python 3.5.1, the minimum operating system requirement is Windows 7 with SP1. For versions 3.0 through 3.4.x, Windows XP is acceptable.
Linux Platforms
Different flavors of Linux use different package managers to install new packages.
On Ubuntu Linux, Python 3 is installed using the following command in a terminal.
$sudo apt-get install python3-minimal
Install from source
Download the Gzipped source archive from the Python download address: – https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
Extract the tarball
tar xvfz Python-3.5.1.tgz
Configure and Install:
cd Python-3.5.1
./configure --prefix = /opt/python3.5.1
make
sudo make install
Mac OS
Download the Mac OS installer from this website: – https://www.python.org/downloads/mac-osx/
- Mac OS X 64-bit/32-bit Installer – python-3.5.1-macosx10.6.pkg
- Mac OS X 32-bit i386/PPC Installer – python-3.5.1-macosx10.5.pkg
Double-click the package file and follow the wizard’s instructions to install it.
The latest and most current source code, binaries, documentation, news, and more can be found on the official Python website —
Python Official Website –https://www.python.org/
You can download the Python documentation from the following website. These documents are available in HTML, PDF, and PostScript formats.
Python Documentation Website – www.python.org/doc/
Setting Your PATH
Programs and other executable files can be located in many directories. Therefore, the operating system provides a search path that lists the directories it searches for executable files.
The important features are:
- The path is stored in an environment variable, a named string maintained by the operating system. This variable contains information available to the command shell and other programs.
-
The path variable is named PATH on Unix and Path on Windows (Unix is case-sensitive, Windows is not).
-
On Mac OS, the installer handles the details of the path. To call the Python interpreter from any specific directory, you must add the Python directory to your path.
Setting the Path in Unix/Linux
In Unix, to add the Python directory to the path for a particular session—
- In a csh shell – Type setenv PATH “$PATH:/usr/local/bin/python3” and press Enter.
-
In a bash shell (Linux) – Type export PYTHONPATH=/usr/local/bin/python3.4 and press Enter.
-
In a sh or ksh shell – Type PATH=”$PATH:/usr/local/bin/python3” and press Enter.
Note – /usr/local/bin/python3 is the path to your Python directory.
Setting Your Path in Windows
To add the Python directory to your path for a specific session in Windows:
- At the command prompt, type path %path%;C:Python and press Enter.
Note – C:Python is the path to your Python directory.
Running Python
There are three different ways to start Python:
The Interactive Interpreter
You can start Python from Unix, DOS, or any other system that provides a command-line interpreter or shell window.
Type python at the command line.
Start coding immediately in the interactive interpreter.
$python # Unix/Linux
or
python% # Unix/Linux
or
C:>python # Windows/DOS
Integrated Development Environment
If you have a GUI application that supports Python on your system, you can also run Python from a graphical user interface (GUI) environment.
- Unix – IDLE is the first Unix IDE for Python.
-
Windows – PythonWin is the first Windows interface for Python, an IDE with a graphical user interface.
-
Macintosh – The Macintosh versions of Python and the IDLE IDE are available from the main website as MacBinary or BinHex’d downloads.
If you have trouble setting up your environment correctly, you can get help from your system administrator. Make sure your Python environment is set up correctly and working properly.
Note – All examples given in subsequent chapters are based on Python 3.4.1, available on Windows 7 and Ubuntu Linux.
We have set up a Python programming environment online so that you can run all available examples online while learning the theory. Feel free to modify any example and run it online.