How To Install python-parso on Ubuntu 18.04

In this tutorial we learn how to install python-parso on Ubuntu 18.04. python-parso is Python parser that supports error recovery

Introduction

In this tutorial we learn how to install python-parso on Ubuntu 18.04.

What is python-parso

python-parso is:

Parso is a Python parser that supports error recovery and round-trip parsing for different Python versions (in multiple Python versions). Parso is also able to list multiple syntax errors in your Python file.

Parso has been battle-tested by jedi. It was pulled out of jedi to be useful for other projects as well.

Parso consists of a small API to parse Python and analyse the syntax tree.

A simple example:

import parso module = parso.parse(‘hello + 1’, version=“3.6”) expr = module.children[0] expr PythonNode(arith_expr, [<Name: hello@1,0>, <Operator: +>, <Number: 1>]) print(expr.get_code()) hello + 1 name = expr.children[0] name <Name: hello@1,0> name.end_pos (1, 5) expr.end_pos (1, 9)

To list multiple issues:

grammar = parso.load_grammar() module = grammar.parse(‘foo +\nbar\ncontinue’) error1, error2 = grammar.iter_errors(module) error1.message ‘SyntaxError: invalid syntax’ error2.message “SyntaxError: ‘continue’ not properly in loop”

There are three methods to install python-parso on Ubuntu 18.04. We can use apt-get, apt and aptitude. In the following sections we will describe each method. You can choose one of them.

Install python-parso Using apt-get

Update apt database with apt-get using the following command.

sudo apt-get update

After updating apt database, We can install python-parso using apt-get by running the following command:

sudo apt-get -y install python-parso

Install python-parso Using apt

Update apt database with apt using the following command.

sudo apt update

After updating apt database, We can install python-parso using apt by running the following command:

sudo apt -y install python-parso

Install python-parso Using aptitude

If you want to follow this method, you might need to install aptitude first since aptitude is usually not installed by default on Ubuntu. Update apt database with aptitude using the following command.

sudo aptitude update

After updating apt database, We can install python-parso using aptitude by running the following command:

sudo aptitude -y install python-parso

How To Uninstall python-parso on Ubuntu 18.04

To uninstall only the python-parso package we can use the following command:

sudo apt-get remove python-parso

Uninstall python-parso And Its Dependencies

To uninstall python-parso and its dependencies that are no longer needed by Ubuntu 18.04, we can use the command below:

sudo apt-get -y autoremove python-parso

Remove python-parso Configurations and Data

To remove python-parso configuration and data from Ubuntu 18.04 we can use the following command:

sudo apt-get -y purge python-parso

Remove python-parso configuration, data, and all of its dependencies

We can use the following command to remove python-parso configurations, data and all of its dependencies, we can use the following command:

sudo apt-get -y autoremove --purge python-parso

References

Summary

In this tutorial we learn how to install python-parso package on Ubuntu 18.04 using different package management tools: apt, apt-get and aptitude.