Python red hat linux

Learn Python: Tutorials and updates from Red Hat experts

Python is a popular programming language for data science, machine learning, and web development.

Install Python 3 on RHEL

Updating to Python 3.9 is a great way to modernize your existing applications with the latest Python features, including time zone-aware timestamps, new string functions, dictionary union operators, and subtle performance boosts.

You can install Python 3.9, set up your environment, and start using it to create and run Python web services in a Red Hat Enterprise Linux 8 container in 15 minutes.

Why do developers love Python?

«I love Python because it’s fast to write, smooth, looks clean, offers many clever (to the point of dangerous) ways to do things and combine them, and has useful libraries and web frameworks for just about anything you want to do.»

Are you ready to learn Python? This quick video could help you decide.

Get a first look at five language features that make Python powerful, versatile, and easy to use.

What is Python used for?

Python is a server-side programming language that’s been a fixture in programming since it was introduced in the late ’80s. And why not? It’s easy to read, write, and run; it’s more efficient than similar languages with the same functions; and it’s more scalable.

Here are a few reasons why Python is hotter than ever.

More people are using it

The days of technology companies and developers being the only ones interested in data analytics and data modeling are over. Python libraries let users analyze data trends, identify gaps, and pivot quickly to solutions. Its readability and simple syntax make it a great choice for these and other applications.

Читайте также:  Kali linux how to install on usb

Data science and machine learning

Python is second only to R for data science and data analytics, and it can do so much more. Many organizations choose Python for their data processing workloads and analysis, including applications in machine learning, artificial intelligence, and web development.

Hundreds of Python libraries and frameworks

Python has seen thousands of hours of open source development, resulting in a rich ecosystem of libraries and tools for just about anything you want to do. No matter what you need, Python gives developers and builders a wealth of tools to choose from.

It’s an interpreted language

Why do developers love interpreted languages? If you’re able to implement instructions freely and outside a machine language program, you don’t have to use a compiler to execute your code; you can run your code as soon as you write it and see immediate results.

Источник

Chapter 36. Introduction to Python

Python is a high-level programming language that supports multiple programming paradigms, such as object-oriented, imperative, functional, and procedural paradigms. Python has dynamic semantics and can be used for general-purpose programming.

With Red Hat Enterprise Linux, many packages that are installed on the system, such as packages providing system tools, tools for data analysis, or web applications, are written in Python. To use these packages, you must have the python* packages installed.

36.1. Python versions

Two incompatible versions of Python are widely used, Python 2.x and Python 3.x. RHEL 8 provides the following versions of Python.

Table 36.1. Python versions in RHEL 8

Each of the Python versions up to 3.9 is distributed in a separate module. Python 3.11 is distributed as a suite of non-modular RPM packages, including the python3.11 package.

You can install multiple Python versions in parallel on the same RHEL 8 system.

Always specify the version of Python when installing it, invoking it, or otherwise interacting with it. For example, use python3 instead of python in package and command names. All Python-related commands must also include the version, for example, pip3 , pip2 , pip3.8 , pip3.9 , or pip3.11 .

The unversioned python command ( /usr/bin/python ) is not available by default in RHEL 8. You can configure it using the alternatives command; for instructions, see Configuring the unversioned Python.

Читайте также:  Linux distros with bspwm

Any manual changes to /usr/bin/python , except changes made using the alternatives command, might be overwritten upon an update.

As a system administrator, use Python 3 for the following reasons:

  • Python 3 represents the main development direction of the Python project.
  • Support for Python 2 in the upstream community ended in 2020.
  • Popular Python libraries are discontinuing Python 2 support in upstream.
  • Python 2 in Red Hat Enterprise Linux 8 will have a shorter life cycle and aims to facilitate a smoother transition to Python 3 for customers.

For developers, Python 3 has the following advantages over Python 2:

  • Python 3 enables you to write expressive, maintainable, and correct code more easily.
  • Code written in Python 3 will have greater longevity.
  • Python 3 has new features, including asyncio , f-strings, advanced unpacking, keyword-only arguments, and chained exceptions.

However, legacy software might require /usr/bin/python to be configured to Python 2. For this reason, no default python package is distributed with Red Hat Enterprise Linux 8, and you can choose between using Python 2 and 3 as /usr/bin/python , as described in Configuring the unversioned Python.

System tools in Red Hat Enterprise Linux 8 use Python version 3.6 provided by the internal platform-python package. Red Hat advises customers to use the python36 package instead.

36.2. Notable differences between Python versions

Python versions included in RHEL 8 differ in various aspects.

Python bindings

The python38 and python39 modules and the python3.11 package suite do not include the same bindings to system tools (RPM, DNF, SELinux, and others) that are provided for the python36 module. Therefore, use python36 in instances where the greatest compatibility with the base operating system or binary compatibility is necessary. In unique instances where system bindings are necessary together with later versions of various Python modules, use the python36 module in combination with third-party upstream Python modules installed through pip into Python’s venv or virtualenv environments.

Python 3.11 virtual environments must be created using venv instead of virtualenv

The virtualenv utility in RHEL 8, provided by the python3-virtualenv package, is not compatible with Python 3.11. An attempt to create a virtual environment by using virtualenv will fail with the following error message:

$ virtualenv -p python3.11 venv3.11 Running virtualenv with interpreter /usr/bin/python3.11 ERROR: Virtual environments created by virtualenv < 20 are not compatible with Python 3.11. ERROR: Use python3.11 -m venv instead.

To create Python 3.11 virtual environments, use the python3.11 -m venv command instead, which uses the venv module from the standard library.

Читайте также:  Apt get linux headers debian

Источник

Chapter 2. Installing and using Python

In RHEL 9, Python 3.9 is the default Python implementation. Since RHEL 9.2, Python 3.11 is available as the python3.11 package suite.

The unversioned python command points to the default Python 3.9 version.

2.1. Installing Python 3

The default Python implementation is usually installed by default. To install it manually, use the following procedure.

Verification steps

  • To verify the Python version installed on your system, use the —version option with the python command specific for your required version of Python .
  • For Python 3.9 :

2.2. Installing additional Python 3 packages

Packages prefixed with python3- contain add-on modules for the default Python 3.9 version. Packages prefixed with python3.11- contain add-on modules for Python 3.11 .

    To install the Requests module for Python 3.9 , use:

# dnf install python3-requests

Additional resources

2.3. Installing additional Python 3 tools for developers

Additional Python tools for developers are distributed mostly through the CodeReady Linux Builder (CRB) repository.

The python3-pytest package and its dependencies are available in the AppStream repository.

The CRB repository contains, for example, the following packages:

  • python3*-idle
  • python3*-debug
  • python3*-Cython
  • python3.11-pytest and its dependencies.

The content in the CodeReady Linux Builder repository is unsupported by Red Hat.

To install packages from the CRB repository, use the following procedure.

    Enable the CodeReady Linux Builder repository:

# subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpms
# dnf install python3-Cython
# dnf install python3.11-Cython

Additional resources

2.4. Using Python

The following procedure contains examples of running the Python interpreter or Python -related commands.

Prerequisites

  • Ensure that Python is installed.
  • If you want to download and install third-party applications for Python 3.11 , install the python3.11-pip package.

    To run the Python 3.9 interpreter or related commands, use, for example:

$ python3 $ python3 -m venv --help $ python3 -m pip install package $ pip3 install package
$ python3.11 $ python3.11 -m venv --help $ python3.11 -m pip install package $ pip3.11 install package

Источник

Оцените статью
Adblock
detector