How to install and use pipx in Linux?

pipx is a tool for managing and running Python packages that provides an isolated Python environment in which you can install and run various Python tools and applications. This article will introduce in detail the steps and methods of installing and using pipx on the Linux system.

install pipx

Before starting, make sure you have installed Python and the pip package manager. Typically, Linux distributions come with Python and pip pre-installed by default.

Here are the steps to install pipx on a Linux system:

  1. Install pipx using pip by opening a terminal and running the following command:
pip install --user pipx

This will install pipx in the current user's home directory.

  1. Configure environment variables:

By default, pipx will install executable files into ~/.local/binthe directory, so you need to add this directory to the environment variables of the system so that you can access the tools installed by pipx from any location.

Edit ~/.bashrcthe or ~/.bash_profilefile (depending on your shell), and add the following line:

export PATH="$HOME/.local/bin:$PATH"

Save the file and execute the following command for the changes to take effect:

source ~/.bashrc

or

source ~/.bash_profile
  1. Verify installation:

Verify that pipx was successfully installed by running the following command:

pipx --version

If the version information of pipx is output, it means the installation is successful.

So far, you have successfully installed pipx on the Linux system.

use pipx

Once pipx is installed, you can start using it to manage and run Python tools and applications. Here are some common pipx commands and usage examples:

  • Install a Python tool :
pipx install <package>

<package>is the name of the Python tool to install.

Example:

pipx install pylint

This will install and create a separate environment using pipx to run the pylint tool.

  • List installed tools :
pipx list

This will list all tools that the current user has installed using pipx.

  • Run an installed tool :
pipx run <package>

<package>is the name of the installed tool.

Example:

pipx run pylint

This will run the pylint tool in the current environment.

  • Uninstall an installed tool :
pipx uninstall <package>

<package>is the name of the tool to uninstall.

Example:

pipx uninstall pylint
  • To update an installed tool :
pipx upgrade <package>

<package>is the name of the tool to update.

Example:

pipx upgrade pylint

This will update the installed pylint tools with pipx.

  • Install an executable Python script :
pipx install <script_url>

<script_url>is the URL to the executable Python script.

Example:

pipx install https://example.com/myscript.py

This will install with pipx and create an isolated environment to run the specified Python script.

  • Help and Documentation :

You can get help and documentation for pipx at any time by running:

pipx --help

Alternatively, you can check pipx's official documentation and instructions for more detailed information and example usage.

These are some common pipx commands and usage examples. You can install, upgrade, run, and uninstall accordingly according to your needs and usage scenarios.

Summarize

This article introduces the steps and methods of installing and using pipx on Linux system in detail. By using pipx, you can easily manage and run various Python tools and applications without worrying about dependency conflicts or environmental interference. I hope this article provides help and guidance for you to use pipx on Linux systems, and enables you to perform Python development and management more effectively.

Guess you like

Origin blog.csdn.net/weixin_43025343/article/details/131427399