Python Tools and Software

Discussion in 'Shell / Command Line' started by DevynCJohnson, Jul 27, 2014.

  1. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,336
    Likes Received:
    1,073
    Trophy Points:
    113
    Python is a popular cross-platform scripting language. This means Python code can be used on many operating systems and architectures. Understanding Python implementations can help developers with their projects. Also, many people get confused by the many Python implementations and consoles, so I will also discuss some consoles and implementations to help give readers a better understanding of some of this Python software.


    Versions

    Many people may here about Python2 and Python3. Python2 is the older version that has long-term support. Python3 is the newest version. The two differ a little in syntax and available commands. In general, developers should use Python3 when designing a program.

    Python2 Hashpling:
    #!/usr/bin/env python
    #!/usr/bin/env python2

    Python3 Hashpling:
    #!/usr/bin/env python3
    Python3.4 Hashpling (specify minor release):
    #!/usr/bin/env python3.4

    Users can run the Python2 interpreter in a terminal by typing "python", "python2", "python2.7", etc. to run Python2. Alternately, users can use Python3 by typing "Python3" or specifying a specific version. Typing "Python2" or "Python3" will run the latest version of Python2 or Python3, respectively. Yes, users may have multiple Python releases installed on their system with other releases and not have conflicts or errors arise. (https://www.python.org/)

    python1.png

    Users can run executable Python scripts by clicking them like a normal executable as long as the script uses a proper hashpling and the executable-bit in permissions is turned on (enabled). Alternately, users can execute scripts in a terminal by typing something like one of the lines below (type the correct Python command for your script). Or, if the script has a proper hashpling and execute permissions, treat it like a normal executable (./script.py).

    Code:
    python -c /SCRIPT/PATH.py
    python2 -c /SCRIPT/PATH.py
    python3 -c /SCRIPT/PATH.py
    

    Consoles

    Various Python consoles exist. These are like terminals dedicated to Python.

    IPython is an interactive Python console that offers various tools for testing the Python code. IPython is also used for displaying plots and charts via matplotlib. IPython is available for Python 2 and 3. (http://ipython.org/)

    python2.png

    IDLE (Integrated DeveLopment Environment) is a lot like IPython, but with less features, but still enough to satisfy the needs of many developers. IDLE is available for both versions of Python.

    python3.png

    Bpython looks like a terminal, but it has many more features than running Python in a shell-terminal. Bpython supports Python2 and Python3.
    (http://bpython-interpreter.org/)
    (https://pypi.python.org/pypi/bpython)
    (http://docs.bpython-interpreter.org/)
    (http://docs.bpython-interpreter.org/tips.html)

    python4.png

    Dreampie is another Python console, and it is a lot like Bpython. However, Dreampie supports Python 2 and 3. (http://www.dreampie.org/)

    python5.png

    Pycrust is yet another console. Pycrust typically comes as part of a package called “Py”. Py is a collection of tools for wxPython development. It is possible to find a stand-alone Pycrust program. (http://www.wxpython.org/py.php)


    Implementations

    Many implementations of Python exist, but what do I mean by that? Well, there is other software that supports the Python programming language, but they have extra features or a different way of working. "Python" is the language, and an implementation is the interpreting environment. When users execute a standard Python script or use the "python*" shell commands in a terminal, they are using the CPython implementation (not to be confused with Cython). In other words, using the terminal-based interpreter executes code in the CPython environment. Most of the Python code people execute is processed in the CPython implementation. Each implementation has its uses and unique features. (https://wiki.python.org/moin/PythonImplementations)

    NOTE: Sometimes, "CPython" is used to refer to a dialect of Python rather than the main interpreter.

    CPython is the default implementation, environment, or interpreter (which ever term you prefer). Scripts are typically executed in this interpreter. CPython is the official Python interpreter and is often referred to as the "reference implementation" since it follows the Python language specifications completely and defines the language. CPython is written in C and converts the Python code to bytecode on execution of the code. Thus, CPython is a bytecode interpreter. When users download and install Python from the official website or from a software repository (like "apt-get" or "yum"), they are installing the CPython interpreter.

    NOTE: Often times, the term "implementation" and "interpreter" are used interchangeably.

    FUN FACT: Your Python code itself is not being executed. Rather, the task is performed by the interpreter which is written in C.

    PyPy is an implementation that is a lot like CPython, but the interpreter itself is written in Python. Yes, the developers of this interpreter wrote a Python interpreter in Python. However, the code for the interpreter is converted to C and then compiled. PyPy is supposed to perform faster than CPython. While CPython converts interpreted code to bytecode, PyPy converts code to machine-code. (http://pypy.org/)

    NOTE: Machine-code is a set of instructions executed by the computer's CPU directly. Most programming languages are compiled to machine-code like when developers use gcc (or some other compiler) to compile their C-code to make a binary executable. Bytecode is an instruction set that is read by the interpreter and then the interpreter tells the CPU what to do. Such interpreters are often called virtual-machines, runtime-environments, or just-in-time (JIT) compilers.

    Psyco is an old interpreter that was a lot like PyPy. PyPy has taken the place of Psyco. When possible, use PyPy instead of Psyco.

    Jython is an implementation written in Java. Jython allows developers to write Python code, but use Java libraries in addition to Python libraries (modules). Jython can be used as a just-in-time compiler, meaning the Python code is converted to Java bytecode (not Java source code) on runtime and then executed by the Java Runtime Environment (JRE). Alternately, programmers can have Jython compile the Python code to a jar file. The jar is then a standard jar file that users can run like any other jar file. This allows Python programmers to make Java programs. However, such programmers need to at least know about the available Java libraries, but then the programmers can still use Python's usual syntax. As a jar file, the usual Java runtime environment executes the code. Also, users can use Jython in a terminal by typing "jython", or some Python consoles can be set to use Jython instead of CPython. Python scripts that are intended for Jython use a different hashpling than normal scripts (#!/usr/bin/env jython). Jython is compatible with Python2. (http://www.jython.org/)

    python7.png

    NOTE: Users can also use OpenJDK instead of Oracle's Java runtime environment (JRE). OpenJDK is an open-source JRE.

    IronPython is an implementation written in C# for the .NET framework and Mono. IronPython is compatible with Silverlight and can be executed in web-browsers when used with Gestalt (http://gestalt.codeplex.com/) (http://visitmix.com/work/gestalt/). IronPython is Python2 compatible. However, CPython and IronPython operate differently causing rare instances where code may work on one implementation, but not the other. (http://ironpython.net/)

    NOTE: Mono is an open-source framework that offers .NET-compatible tools.

    CLPython is a deprecated implementation written in Common Lisp. It once allowed Python code and Common Lisp code to be mixed as well as libraries from both languages. Python 2 was supported. (http://common-lisp.net/project/clpython/)

    PyS60 (Python for S60) is a deprecated implementation that was a port for Nokia's S60 platform.

    ActivePython is an implementation that is CPython distributed with some extra extensions. ActivePython is distributed by ActiveState. This implementation is Python2 and 3 compatible. (http://www.activestate.com/activepython)

    Cython (not CPython) is an implementation that allows Python to be converted to C/C++ code or use various C/C++ libraries/files. In other words, Cython is a bridge between C/C++ and Python. Cython is also a dialect of Python (discussed later). Developers can also use Cython to execute Python scripts resulting in faster execution than CPython. In addition, developers can make a Python script and use Cython to create a compiled library file (*.so on Unix or *.dll on Windows) that can be used as a Python module. Cython scripts usually use the *.pyx file-extension. The "setup.py" files that are commonly associated with Cython are like "Makefiles" for C/C++ source code. Cython is Python 2 and 3 compatible. (http://cython.org/)

    NOTE: Python modules and libraries are the same thing, just different names.

    As mention above, Cython is an implementation fully compatible with the Python 2 and 3 languages. However, Cython is also a dialect of Python. A dialect computer language is a computer language (in this case Cython) still belonging to a particular language (in this case Python). However, the dialect has some minor variations. Dialects may have less or more features or commands. Scripts for the Cython interpreter can be written using Python code, or developers can use some Cython specific features which allow the code to be more easily and efficiently converted to C/C++ code. Using more Cython-specific code will very likely make the resulting program execute more swiftly and efficiently compared to the CPython or Cython interpreter reading Python code. Other Python dialects include RPython (used to write the PyPy interpreter), CPython, and Stackless-Python.

    QPython is an Android port of the CPython interpreter. QPython comes with the Android module for Python (import android). QPython can be found on Google Play. QPython reads code written in the CPython dialect.
    (http://qpython.com/)
    (http://wiki.qpython.org/)

    Kivy is an open-source framework (with a Python interpreter) that runs on Android, iOS, Windows, Linux, MeeGo, Android SDK, and OS X. Python3 is supported, and the developers are developing support for Cython compatibility with the Python3. (http://kivy.org)

    SL4A (Scripting Layer for Android) is a compatibility layer that allows Android to execute various scripting languages. SL4A has various parts and the part we are interested in is “Py4A” (Python for Android). Py4A is a form of CPython for Android.
    (https://github.com/damonkohler/sl4a)
    (https://code.google.com/p/android-scripting/)
    (https://code.google.com/p/python-for-android/)

    Various other implementations and dialects exist as well as many forks and ports of the different implementations. For example, WPython is a derivative of CPython that uses wordcode rather than bytecode (wordcode uses 16-bits instead of 8-bits). DSPython is another derivative of CPython; this one is for Nintendo's DS-console.



    Many Python implementations exist, each with a special purpose or feature. Developers interested in Python can learn about many more implementations at (https://wiki.python.org/moin/PythonImplementations). For those of you eager to learn Python, you can read the documentation for Python2 (https://docs.python.org/2/) or Python3(https://docs.python.org/3/). For those of you that already know Python, you can strengthen your skills with Cython (http://docs.cython.org/) and RPython (http://pypy.readthedocs.org/en/latest/getting-started-dev.html). Understanding the different implementations can greatly sharpen a Python-scriptwriter's skills and abilities as well as help general computer users have a better understanding of the computer world.

    Attached Files:

    Last edited: Sep 15, 2014
    spin89 and dslackw like this.
  2. Rodrigo

    Rodrigo Member

    Messages:
    30
    Likes Received:
    11
    Trophy Points:
    8
    Wow a very good information about python. I use virtualenv to handle the diferent version of the same library and update-alternatives in Debian to switche between versions of python.


    Thaks for the info.
    DevynCJohnson likes this.
  3. Eric Hansen

    Eric Hansen Moderator Staff Writer

    Messages:
    124
    Likes Received:
    87
    Trophy Points:
    28
    I'm kind of shocked, you don't mention IPython at all from what I saw. Its the most popular one, especially when it comes to scientific and numeric projects.

    But, that's the thing with Python. Its nature has provided a severe extendibility to it, so you have a million choices to do any one thing, and its not wrong, but there might be a better option out there.
    DevynCJohnson likes this.
  4. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,336
    Likes Received:
    1,073
    Trophy Points:
    113
    IPython is a console (look under the "console" heading). For this article, I wanted to primarily discuss the implementations rather than the consoles. IPython uses CPython by default. However, typing "%load_ext cythonmagic" loads the Cyhon capabilities (remember to use %cython or %%cython before entering Cython code)

    http://nbviewer.ipython.org/github/...ocs/examples/notebooks/cython_extension.ipynb
  5. Polyatomic

    Polyatomic New Member

    Messages:
    2
    Likes Received:
    1
    Trophy Points:
    3
    Exellent looking desktop man. Python is so interesting I always get sidetracked when trying to learn the learn the default interpreter from online docs, I will always find another python environment and or interpreter to read about. Your posts are excellent.
    DevynCJohnson likes this.
  6. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,336
    Likes Received:
    1,073
    Trophy Points:
    113
    Thanks for the compliments.

    Imagine if a Python website hired me to write Python articles, then people like you could read more. Since this website is Linux.org, my articles pertain to Linux in some way and I try to cover a variety of topics.
  7. ZHANG/ZHIKUN

    ZHANG/ZHIKUN New Member

    Messages:
    18
    Likes Received:
    2
    Trophy Points:
    3
    thank you, a very good introduction to python. I will try it these few days.
    DevynCJohnson likes this.
  8. pythonuser

    pythonuser New Member

    Messages:
    1
    Likes Received:
    1
    Trophy Points:
    1
    bpython supports both Python 2 and Python 3.
    DevynCJohnson likes this.
  9. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,336
    Likes Received:
    1,073
    Trophy Points:
    113
    Thanks! I see here (http://docs.bpython-interpreter.org/tips.html) that you are indeed correct. Thanks for sharing that information with us. I will update the article.
  10. jerz4lunch

    jerz4lunch New Member

    Messages:
    19
    Likes Received:
    6
    Trophy Points:
    3
    Sorry that this is off-topic, but could you please tell me where you got that desktop theme? I want to try it!
    Last edited: Sep 16, 2014
    DevynCJohnson likes this.
  11. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,336
    Likes Received:
    1,073
    Trophy Points:
    113
    You are the third person to ask me that (the other two were via email), so I will post my answer here.


    I have multiple OS X themes and icons, so I will list all of the sources.

    NoobsLab is a highly recommended developer (in my opinion)
    (http://www.noobslab.com/)
    (http://www.noobslab.com/p/ppa.html)
    (http://www.noobslab.com/2011/11/themes-collection-for-ubuntu-1110-unity.html)
    (https://launchpad.net/~noobslab)

    ppa:noobslab/icons
    ppa:noobslab/icons2
    ppa:noobslab/potenza
    ppa:noobslab/themes


    WebUpd8 is another favorite of mine
    (http://www.webupd8.org/)
    (https://launchpad.net/~webupd8team)
    (http://www.webupd8.org/p/ubuntu-ppas-by-webupd8.html)
    (http://www.webupd8.org/search/label/eyecandy)
    (https://launchpad.net/~webupd8team/ archive/themes)

    ppa:webupd8team/themes

Share This Page