Python - AtoZ Linux https://atozlinux.com Linux News, Tutorials, Freebies & Many More Wed, 26 Apr 2023 06:11:45 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.2 How To Install Python On Linux https://atozlinux.com/how-to-install-python-on-linux/ https://atozlinux.com/how-to-install-python-on-linux/#respond Wed, 26 Apr 2023 06:11:45 +0000 https://atozlinux.com/?p=125682 How To Install Python On Linux Python is one of the most popular programming languages right now in the world. Almost every operating system supports Python. In this tutorial, we are going to show you a step-by-step guide to installing Python on Linux-based operating systems. How To Install Python On Linux Step 1: Install build-essential […]

The post How To Install Python On Linux first appeared on AtoZ Linux.

]]>
How To Install Python On Linux

Python is one of the most popular programming languages right now in the world. Almost every operating system supports Python. In this tutorial, we are going to show you a step-by-step guide to installing Python on Linux-based operating systems.

How To Install Python On Linux

Step 1:

Install build-essential packages required to build Python.

For Ubuntu And Debian-Based Operating Systems:

sudo apt update
sudo apt install build-essential zlib1g-dev \
libncurses5-dev libgdbm-dev libnss3-dev \
libssl-dev libreadline-dev libffi-dev curl

For Fedora-based operating systems:

sudo dnf groupinstall development

Step 2:

Download the  latest version of Python 3

Download the latest version of Python 3 from the official website of Python. After the download is complete, you will have a .tar.xz archive file (a “tarball”).

Step 3:

Now, Extract the tarball file that you have downloaded in the above command.

tar -xf Python-3.x.x.tar.xz

Step 4:

Navigate to the configure file and execute it in your Linux terminal with:

cd Python-3.*
./configure

Step 5:

To install new Python alongside the version of Python installed on your system:

sudo make altinstall

The build process may take some time.

To replace the current version of Python with this new version, you should uninstall your current Python package using your package manager and then install:

sudo make install

Step 6:

To verify it, run the following commands in your terminal:

python3 --version

or

python --version

If the output says Python 3.x, Python 3 has been successfully installed in your Linux.

 

Create a Python virtual environment in Linux

Run the following command to create a virtual environment:

python3.8 -m venv foldername

To activate the virtual environment, run the following command:

$ source example/bin/activate
(foldername) $

Notice that your terminal prompt ($) is now preceded by an environment name.

To deactivate the virtual environment, simply run the deactivate command:

(foldername) $ deactivate

The post How To Install Python On Linux first appeared on AtoZ Linux.

]]>
https://atozlinux.com/how-to-install-python-on-linux/feed/ 0
How To Use JSONPath In Python https://atozlinux.com/how-to-use-jsonpath-in-python/ https://atozlinux.com/how-to-use-jsonpath-in-python/#respond Tue, 01 Feb 2022 15:45:38 +0000 https://atozlinux.com/?p=151 JSONPath is an expression language and JSONPath Python is a way to parse JSON data. JSONPath provides a simpler syntax to query JSON data and get the desired value in Python. There are many JSONPath libraries for Python. JSON stands for JavaScript Object Notation. JSONPath in Python is similar to the XPath in XML. In […]

The post How To Use JSONPath In Python first appeared on AtoZ Linux.

]]>
JSONPath is an expression language and JSONPath Python is a way to parse JSON data. JSONPath provides a simpler syntax to query JSON data and get the desired value in Python. There are many JSONPath libraries for Python. JSON stands for JavaScript Object Notation. JSONPath in Python is similar to the XPath in XML.

In this article, we will learn how to use JSONPath for Python along with the use of the JSONPath libraries.

How To Use JSONPath In Python

There are many JSONPath libraries in Python. Some of the popular JSONPath libraries are jsonpath-rw, jsonpath-rw-ext, and jsonpath-ng and the most popular one is the jsonpath-ng library. Let us learn how to use JSONPath for Python.

Let’s start by installing the jsonpath-ng library using Python’s Package Manager (pip). To install the jsonpath-ng library, run the following command in our terminal:

pip install jsonpath-ng

You can then import jsonpath-ng in Python using a Python IDE with the following code:

import jsonpath_ng

JSONPath Python Example

Here’s an example of how JSONPath can be used in Python to work with JSON data:

import json
from jsonpath_ng import jsonpath, parse

booksData = ‘{“Category”:”Finance”, “Author”:”Bibek dai” , “Title”:”The blogger’s page”}’
Data = json.loads(booksData)
ParseData= parse(‘$.Category’)
Category = ParseData.find(Data)
ParseData1= parse(‘$.Author’)
Author = ParseData1.find(Data)
ParseData2= parse(‘$.Title’)
Title = ParseData2.find(Data)

print(“The Category of the book is: “, Category[0].value)
print(“The Author of the book is: “, Author[0].value)
print(“The Name of the book is: “, Title[0].value)

The output will be:
The Category of the book is: Finance
The Author of the book is: Bibek Dai
The Name of the book is: The Blogger’s page

JSONPath Python Syntax

JSONPath operators:

Syntax Meaning
jsonpath1 . jsonpath2 All nodes that are matched by jsonpath2 starting at any node matching jsonpath1
jsonpath [ whatever ] Same as jsonpath.whatever
jsonpath1 .. jsonpath2 All nodes that are matched by jsonpath2 that descend from any node matching jsonpath1
jsonpath1 where jsonpath2 Any nodes matching jsonpath1 with a child matching jsonpath2
jsonpath1 | jsonpath2 Any nodes matching the union of jsonpath1 and jsonpath2

The post How To Use JSONPath In Python first appeared on AtoZ Linux.

]]>
https://atozlinux.com/how-to-use-jsonpath-in-python/feed/ 0