Environment Setup, Python is available on a extensive sort of structures consisting of Linux and Mac OS X. Let’s understand how to installation our Python surroundings.
Local Environment Setup
Open a terminal window and kind “python” to find out if it’s far already installed and which model is set up.
- Unix (Solaris, Linux, FreeBSD, AIX, HP/UX, SunOS, IRIX, etc.)
- Win 9x/NT/2000
- Macintosh (Intel, PPC, 68K)
- DOS (a couple of variations)
- Nokia cell phones
- Windows CE
- Acorn/RISC OS
- Python has also been ported to the Java and .NET digital machines
Environment Setup, Getting Python
Environment Setup, The maximum up-to-date and modern supply code, binaries, documentation, information, and so forth., is available on the legitimate internet site of Python https://www.Python.Org/
You can download Python documentation from https://www.Python.Org/document/. The documentation is available in HTML, PDF, and PostScript formats.
Environment Setup, Installing Python
Python distribution is available for a extensive variety of structures. You need to down load only the binary code relevant for your platform and deploy Python.
If the binary code for your platform isn’t always available, you want a C compiler to collect the source code manually. Compiling the source code offers greater flexibility in terms of choice of functions that you require in your set up.
Here is a quick evaluate of putting in Python on various systems −
Environment Setup, Unix and Linux Installation
Environment Setup, Here are the simple steps to install Python on Unix/Linux device.
Open a Web browser and go to https://www.Python.Org/downloads/.
Follow the link to download zipped supply code to be had for Unix/Linux.
Download and extract documents.
Environment Setup, Editing the Modules/Setup record in case you need to personalize some options.
Run ./configure script
make set up
This installs Python at preferred location /usr/local/bin and its libraries at /usr/nearby/lib/pythonXX wherein XX is the version of Python.
Here are the steps to put in Python on Windows system.
Environment Setup, Open a Web browser and visit https://www.Python.Org/downloads/.
Follow the hyperlink for the Windows installer python-XYZ.Msi document in which XYZ is the model you want to put in.
To use this installer python-XYZ.Msi, the Windows machine should assist Microsoft Installer 2.0. Save the installer record for your local gadget and then run it to discover if your system supports MSI.
Run the downloaded record. This brings up the Python install wizard, that’s in reality easy to use. Just accept the default settings, wait until the installation is finished, and you are accomplished.
Environment Setup, Macintosh Installation
Recent Macs come with Python installed, but it is able to be several years obsolete. See http://www.Python.Org/down load/mac/ for instructions on getting the current version together with greater gear to support improvement at the Mac. For older Mac OS’s before Mac OS X 10.3 (released in 2003), MacPython is available.
Jack Jansen continues it and you could have full get right of entry to to the whole documentation at his website − http://www.Cwi.Nl/~jack/macpython.Html. You can find complete set up details for Mac OS installation.
Environment Setup, Setting up PATH
Programs and other executable files may be in lots of directories, so operating systems provide a search route that lists the directories that the OS searches for executables.
The course is stored in an environment variable, that’s a named string maintained by means of the working system. This variable includes records to be had to the command shell and different applications.
The route variable is named as PATH in Unix or Path in Windows (Unix is case touchy; Windows isn’t always).
Environment Setup, In Mac OS, the installer handles the course details. To invoke the Python interpreter from any unique listing, you ought to upload the Python listing on your direction.
Setting path at Unix/Linux
To add the Python directory to the route for a selected consultation in Unix −
Environment Setup, In the csh shell − type setenv PATH “$PATH:/usr/neighborhood/bin/python” and press Enter.
In the bash shell (Linux) − kind export PATH=”$PATH:/usr/neighborhood/bin/python” and press Enter.
In the sh or ksh shell − type PATH=”$PATH:/usr/neighborhood/bin/python” and press Enter.
Note − /usr/nearby/bin/python is the route of the Python listing
Setting path at Windows
To upload the Python listing to the path for a particular session in Windows −
At the command activate − type route %direction%;C:Python and press Enter.
Note − C:Python is the route of the Python directory
Python Environment Variables
Here are important environment variables, which can be recognized by Python −
|Sr.No.||Variable & Description|
|1||PYTHONPATHIt has a role similar to PATH. This variable tells the Python interpreter where to locate the module files imported into a program. It should include the Python source library directory and the directories containing Python source code. PYTHONPATH is sometimes preset by the Python installer.|
|2||PYTHONSTARTUPIt contains the path of an initialization file containing Python source code. It is executed every time you start the interpreter. It is named as .pythonrc.py in Unix and it contains commands that load utilities or modify PYTHONPATH.|
|3||PYTHONCASEOKIt is used in Windows to instruct Python to find the first case-insensitive match in an import statement. Set this variable to any value to activate it.|
|4||PYTHONHOMEIt is an alternative module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directories to make switching module libraries easy.|
There are three distinct approaches to start Python −
You can begin Python from Unix, DOS, or another system that provides you a command-line interpreter or shell window.
Enter python the command line.
Start coding right away in the interactive interpreter.
$python # Unix/Linux
python% # Unix/Linux
C:> python # Windows/DOS
Here is the list of all the available command line options −
|Sr.No.||Option & Description|
|1||-dIt provides debug output.|
|2||-OIt generates optimized bytecode (resulting in .pyo files).|
|3||-SDo not run import site to look for Python paths on startup.|
|4||-vverbose output (detailed trace on import statements).|
|5||-Xdisable class-based built-in exceptions (just use strings); obsolete starting with version 1.6.|
|6||-c cmdrun Python script sent in as cmd string|
|7||filerun Python script from given file|
Script from the Command-line
A Python script may be carried out at command line with the aid of invoking the interpreter to your software, as within the following −
$python script.py # Unix/Linux
python% script.py # Unix/Linux
C: >python script.py # Windows/DOSNote − Be sure the file permission mode allows execution.
Note − Be sure the file permission mode allows execution.
Integrated Development Environment
You can run Python from a Graphical User Interface (GUI) surroundings as nicely, if you have a GUI application in your machine that helps Python.
- Unix − IDLE is the first actual Unix IDE for Python.
- Windows − PythonWin is the first Windows interface for Python and is an IDE with a GUI.
- Macintosh − The Macintosh model of Python along with the IDLE IDE is to be had from the primary internet site, downloadable as both MacBinary or BinHex’d documents.
If you aren’t able to set up the surroundings well, then you may take assist out of your system admin. Make positive the Python surroundings is properly installation and working flawlessly nice.
Note − All the examples given in next chapters are performed with Python 2.Four.3 model to be had on CentOS flavor of Linux.
We already have installation Python Programming surroundings online, so that you can execute all the available examples on line at the identical time whilst you are studying principle. Feel unfastened to alter any example and execute it on line.