Python Installation under Linux

  

            Python Installation under Linux

  •         Most Linux distributions already contain Python in them. However, the installed Python version may not be the latest one. You can
    check the version as shown below:
    $ python3 –version
        check the version as shown below:
         $ python3 –version

  •           If you find that the version is not the latest one, then you can install
    it using the command:
    $ sudo apt-get install python3.8
           it using the command:
           $ sudo apt-get install python3.8

{tocify} $title= {Table of Contents}

Python Resources

  •          Python source code, binaries and documentation is available at:

              - Python official website: www.python.org (http://www.python.org)

              - Documentation website: www.python.org/doc (http://www.python.org/doc

  •          Program development in Python can be done in 3 ways:

             - Using built-in IDLE.

            - Using third-party IDEs.

            - Using online Python shells.

  •          Third-party development tools and the links from where they can be

downloaded are given below:

- NetBeans IDE for Python:

https://download.netbeans.org/netbeans/6.5/python/ea/ (https://download

- PyCharm IDE for Python:

https://www.jetbrains.com/pycharm (https://www.jetbrains.com/pycharm)

- Visual Studio Code IDE:

https://code.visualstudio.com/download (https://code.visualstudio.com/dow

·         If you do not wish to install any Python development tool on your machine, then you can use any of the following online Python shells:

- https://www.python.org/shell/ (https://www.python.org/shell/)

- https://ideone.com/ (https://ideone.com/)

- https://repl.it/languages/python3 (https://repl.it/languages/python3)

Third-party Packages

  •          Pythonistas in Python community create packages (libraries) and makes it available for use for other programmers. They use PyPI— Python Package Index (www.pypi.org) to distribute their packages. PyPI maintains the list of such third-party Python packages available.
  •          There are third-party packages available for literally doing everything under the sun. Some packages that are popularly used for creating Data Science applications include:

- NumPy: Advanced mathematical operations library with support for large multi-dimensional arrays and matrices.

- SciPy: Scientific computing library for optimization, integration, interpolation, signal processing, image processing, etc.

- Pandas: Library for manipulating numerical tables and time series.

- MatPlotLib: 2D and 3D Data visualization library.

- OpenCV: Open source Computer vision library.

·         You too can register at PyPI and upload your packages there. You should follow the guidelines given at www.pypi.org  to create the package, build it and upload it to the Python Package Index.

·          pip is a commonly used tool for installing packages from PyPI. This tool gets installed when you install Python.

More Sophisticated Tools

·         Many tools have come into existence to help Python programmers build and document their Data Science and Artificial Intelligence applications. These include:

- Jupyter Notebook - It is a very flexible browser-based tool that lets us to interactively work with Python (and many other languages). It lets us put our Python code, output of the code and any kind of visualization or plot etc. in the same document called Notebook. It is a great tool doing modular program development.

- Google Colab - This tool provides a free Jupyter notebook environment to execute code on Google's cloud servers. As a result, you can leverage the power of Google's hardware.

- Spyder - This tool provides a Scientific Python Development Environment with sophisticated testing and debugging features.

·         Both Jupyter and Spyder are part of a very popular software distribution called Anaconda. So once you download and install Anaconda, you get Jupyter and Spyder ready-made.

Traditional Compilation Approach in C, C++

Traditional Compilation Approach

·         Approach used in compilation and execution method in traditional language (C, C++) is different as compared to newer languages like (Python, Java, C#).

·         These different approaches stem from the goal of achieving speed versus portability (ability of using the same program on multiple platforms).

·         A platform is a combination of microprocessor and OS. For Example, ARM microprocessor + Android OS, Intel x86 + Windows 10, ect.

·         Each microprocessor uses a different instruction Sets. Each OS platforms Input/ Output and manages memory in different ways.

·         Programs written in C and C++ are converted into machine language using compilers that are targeted for a particular Microprocessor + OS combination.

·         The machine language instructions are then executed on a platform for which they are created.

Compilation Approach in Python

Modern Compilation Approach

  •          Modern languages like Python, Java and C# use a different approach for program conversion and execution. Let us understand this approach with reference to Python.

  •          A Python virtual Machine (often called PVM or Interpreter) is created for each new architecture. This interpreter is installed when we download and install Python.

  •          A PVM is a software piece that emulates a physical computer. PVM is a stack machine, i.e., it manipulates several stacks to perform its operation (as contrasted with a real register machine, which writes to and reads from particular memory locations).

  •        program written in Python are converted into bytecode instructions by Python compilers. Bytecode instructions remain same irrespective of the microprocessor + OS combination.

  •          During execution bytecode instructions are interpreted by the virtual machine (VM) and then executed.

  •          Major portion of program conversion happens during interpretation stage in Python, it is often considered to be interpreted language.

Pros and Cons of Traditional Approach

  •          The traditional approach used by C and C++ has the advantage of producing programs that executes speedily on real machines.
  •          However, it needs substantial effort to create good compilers for each new platform.
  •          Also, the execution code created for one platform does not work on another platform. That is why programs created for Windows + x86 do not on a Linux + ARM platform and vice versa.

Pros and Cons of Modern Approach

  •          The modern approach used by Python, Java, C# has two distinct advantages:

·       It is much easier to port VM to a new architecture as a compared to writing a conventional compiler for a new architecture.

·         Same Python program can work for any architecture for which a PVM is available. That gives Python programs portability.

         ·            The disadvantage of PVM approach is that it adds an extra layer of Software which reduces performance.

Working with Python

  •                 Once Python is installed, program development can be done using the built-in Python Integrated Development and Learning Environment (IDLE).
  •                IDLE is a good development tool. It offers handy features like syntax highlighting, context-sensitive help and debugging.
  •                   Syntax highlighting feature display keywords, functions, methods and strings in different colors making it easy to identify them.
  •                 Context-sensitive help can be obtained by pressing Ctrl Space wherever you need help as you type the program. This is immensely useful since it is almost impossible to remember names of all functions and methods and their parameters.
  •                Debugger lets you locate any logical errors that you may have committed in your program by allowing you trace the flow of execution of the program. This tracing can be done a step at a time by setting up break points and by single stepping through the program. As you do so IDLE lets you watch the values of different variables as they change during execution.

Python Programming Modes

  •                      Python can be used in two modes:

- Interactive mode - used for exploring Python syntax, seek help and debug short programs.

- Script mode - used for writing full-fledged Python programs.

         ·            Both modes are supported by IDLE (Python Integrated Development and Learning Environment).

  •                      To use IDLE in Interactive mode:

- Locate it in Windows by typing IDLE in Windows search bar and hit enter, or double click the IDLE icon.

- It will open the Python shell window showing >>> Python shell prompt.

- Execute the following Python code at this prompt.

 

>>> print ('Keep calm and bubble on')

- It will display the message 'Keep calm and bubble on' followed

by the >>> prompt.

          ·            To use IDLE in Script mode:

- Launch IDLE. In the IDLE shell window from the menu select File

| New File. A new window will open. Type the following script in it:

 

print ('Those who cannot laugh at themselves…')

print('leave the job to others.')

- Using File | Save and save the script under the name 'Test.py'.

- Execute the script from the Run menu or using F5. The two messages will get printed.

          ·            Instead of IDLE if you decide to use NetBeans or Visual Studio Code for program development then follow the steps given below:

- Create a new Python project ‘Test’.

- Type the script in Test.py.

- Execute the script using F6 in NetBeans or Ctrl F5 in Visual Studio Code.

- On execution it will print the two lines and then you are ready to create another project and another script in it.

Determining Python Version

  •                        Python has evolved over the years. You can determine the version installed on your machine through a simple Python script:

                              import sys

                          print (sys.version)

 

Post a Comment (0)
Previous Post Next Post