translated

This commit is contained in:
geekpi 2023-06-13 09:05:34 +08:00
parent 8ef88396ad
commit 51dc147875
2 changed files with 184 additions and 184 deletions

View File

@ -1,184 +0,0 @@
[#]: subject: "Install and Use pipx in Linux"
[#]: via: "https://itsfoss.com/install-pipx-ubuntu/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Install and Use pipx in Linux
======
Pip is a popular tool for installing Python packages and modules from [Python Package Index][1].
However, in recent distribution versions, pip users are encountering an [externally-managed-environment error][2].
![error: externally-managed-environment][3]
That's a 'feature' added to avoid conflicts between Python packages installed via [Pip][4] and the native package manager. Python wants you to use separate virtual environments instead of installing the package at the global level via Pip.
**This is where pipx comes into the picture**. It creates a new virtual environment for each application you install and then creates links to local binary in the /bin at the global level. All this is automatic. It saves time and effort for you.
Let's see how to install and use Pipx on Ubuntu and other Linux distributions.
### Install pipx on Ubuntu and other Linux
The installation is straightforward and can be installed using the following command on Ubuntu and Debian:
```
sudo apt update && sudo apt install pipx
```
For other distributions, please use your package manager and install it.
Once you are done with the installation, [add it to the $PATH][5] so it can be accessed from everywhere:
```
pipx ensurepath
```
![install pipx in ubuntu][6]
**Close the terminal and start it again**. That's it! Now, let's have a look at how to use it.
### Using pipx
What is the primary use of a package manager? Package installation, updation, and removal.
Let me show how you can do the following with pipx:
- Search packages
- Package installation
- Upgradation
- Package removal
Let's start with the installation.
#### How to install packages using pipx
To install packages using pipx, you'd have to follow a simple command syntax:
```
pipx install <package_name>
```
For example, here, I installed a very useful program Cowsay:
```
pipx install cowsay
```
![install python packages in isolation using pipx in ubuntu][7]
Similarly, if you want to install a specific version of the package, you'd have to insert the version number followed by `==` as shown:
```
pipx install package==version
```
For example, here, I installed numpy version 1.24.1:
```
pipx install numpy==1.24.1
```
![][8]
#### How to search packages
The pipx utility does not have a search feature (because of limited API use of PyPI) but that doesn't mean you can't search Python packages.
To search packages, you'd have to install `pypisearch`:
```
pipx install pypisearch
```
Once you do that, you can search the packages using the `pypisearch` command:
```
pypisearch python_package_name
```
Here, I searched for neofetch:
![search python packages in Ubuntu][9]
#### How to upgrade packages using pipx
Like any other modern package manager, you can upgrade all packages at once or you can upgrade one package at a time.
To upgrade all the packages at once, all you have to do is execute the following command:
```
pipx upgrade-all
```
![upgrade all the python packages at once in ubuntu][10]
As you can see, it upgraded numpy to the latest version.
But if you want to upgrade a specific package, here's how you do it:
```
pipx upgrade package-name
```
Let's say I want to upgrade `cowsay` package to the latest version, then, I will be using the following:
```
pipx upgrade cowsay
```
![upgrade specific python package using pipx in ubuntu][11]
#### How to uninstall packages using pipx
To remove packages, you'd have to use the `uninstall` flag as shown:
```
pipx uninstall package_name
```
For your reference, here, I removed `numpy` from my system:
```
pipx uninstall numpy
```
![remove python packages using pipx in ubuntu][12]
### Pip or Pipx?
The restrictions put on Pip have limited its use by the end users. Thankfully, Pipx provides the much-needed alternative. It meets the Python guidelines of using virtual environments and, at the same time, allows installed applications to be available at the global level.
For end users, who are not Python application developers, this gives the option to use Python applications unavailable in distribution repositories.
I hope you find this tutorial helpful. Let me know if you have questions or suggestions.
--------------------------------------------------------------------------------
via: https://itsfoss.com/install-pipx-ubuntu/
作者:[Sagar Sharma][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lkxed/
[1]: https://pypi.org:443/
[2]: https://itsfoss.com/externally-managed-environment/
[3]: https://itsfoss.com/content/images/2023/05/error--externally-managed-environment.png
[4]: https://itsfoss.com/install-pip-ubuntu/
[5]: https://itsfoss.com/add-directory-to-path-linux/
[6]: https://itsfoss.com/content/images/2023/05/install-pipx-in-ubuntu.png
[7]: https://itsfoss.com/content/images/2023/05/install-python-packages-in-isolation-using-pipx-in-ubuntu.png
[8]: https://itsfoss.com/content/images/2023/05/install-specific-version-of-python-package-in-ubuntu-using-pipx.png
[9]: https://itsfoss.com/content/images/2023/05/search-python-packages-in-Ubuntu.png
[10]: https://itsfoss.com/content/images/2023/05/upgrade-all-the-python-packages-at-once-in-ubuntu.png
[11]: https://itsfoss.com/content/images/2023/05/upgrade-specific-python-package-using-pipx-in-ubuntu.png
[12]: https://itsfoss.com/content/images/2023/05/remove-python-packages-using-pipx-in-ubuntu.png

View File

@ -0,0 +1,184 @@
[#]: subject: "Install and Use pipx in Linux"
[#]: via: "https://itsfoss.com/install-pipx-ubuntu/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
在 Linux 中安装和使用 pipx
======
Pip 是一种流行的工具,用于从 [Python 包索引][1]中安装 Python 包和模块。
然而在最近的发行版本中pip 用户遇到了[外部管理环境错误][2]。
![error: externally-managed-environment][3]
这是为避免通过 [Pip][4] 安装的 Python 包与本机包管理器之间发生冲突而添加的“功能”。Python 希望你使用单独的虚拟环境,而不是通过 Pip 在全局安装包。
**这就是 pipx 发挥作用的地方**。它为你安装的每个应用创建一个新的虚拟环境,然后在全局级别的 /bin 中创建到本地二进制文件的链接。这一切都是自动的。它为你节省时间和精力。
让我们看看如何在 Ubuntu 和其他 Linux 发行版上安装和使用 Pipx。
### 在 Ubuntu 和其他 Linux 上安装 pipx
安装很简单,可以在 Ubuntu 和 Debian 上使用以下命令安装:
```
sudo apt update && sudo apt install pipx
```
对于其他发行版,请使用你的包管理器并安装它。
完成安装后,[将其添加到 $PATH][5] 以便可以从任何地方访问它:
```
pipx ensurepath
```
![install pipx in ubuntu][6]
**关闭终端并重新启动它**。这就完成了! 现在,让我们看看如何使用它。
### 使用 pipx
包管理器的主要用途是什么? 软件包安装、更新和删除。
让我向你展示如何使用 pipx 执行以下操作:
- 搜索包
- 包安装
- 升级
- 包移除
让我们从安装开始。
#### 如何使用 pipx 安装包
要使用 pipx 安装包,你必须遵循一个简单的命令语法:
```
pipx install <package_name>
```
例如,在这里,我安装了一个非常有用的程序 Cowsay
```
pipx install cowsay
```
![install python packages in isolation using pipx in ubuntu][7]
同样,如果你想安装特定版本的包,你必须插入版本号后跟 `==` 如下所示:
```
pipx install package==version
```
例如,在这里,我安装了 1.24.1 版本的 numpy
```
pipx install numpy==1.24.1
```
![][8]
#### 如何搜索包
pipx 程序没有搜索功能(因为 PyPI 的 API 使用有限)但这并不意味着你不能搜索 Python 包。
要搜索包,你需要安装 `pypisearch`
```
pipx install pypisearch
```
完成后,你可以使用 `pypisearch` 命令搜索包:
```
pypisearch python_package_name
```
在这里,我搜索了 neofetch
![search python packages in Ubuntu][9]
#### 如何使用 pipx 升级包
与任何其他现代包管理器一样,你可以一次升级所有包,也可以一次升级一个包。
要一次升级所有软件包,你只需执行以下命令:
```
pipx upgrade-all
```
![upgrade all the python packages at once in ubuntu][10]
如你所见,它将 numpy 升级到最新版本。
但是如果你想升级一个特定的包,你可以这样做:
```
pipx upgrade package-name
```
假设我想将 `cowsay` 包升级到最新版本,那么,我将使用以下命令:
```
pipx upgrade cowsay
```
![upgrade specific python package using pipx in ubuntu][11]
#### 如何使用 pipx 卸载包
要删除包,你必须使用 `uninstall` 标志,如下所示:
```
pipx uninstall package_name
```
为了供你参考,在这里,我从我的系统中删除了 `numpy`
```
pipx uninstall numpy
```
![remove python packages using pipx in ubuntu][12]
### Pip 还是 Pipx
对 Pip 的限制限制了最终用户对它的使用。值得庆幸的是Pipx 提供了急需的替代方案。它符合使用虚拟环境的 Python 准则,同时允许已安装的应用在全局范围内可用。
对于不是 Python 应用开发的最终用户,这提供了使用发行版仓库中不可用的 Python 应用的选项。
希望本教程对你有所帮助。如果你有任何问题或建议,请告诉我。
--------------------------------------------------------------------------------
via: https://itsfoss.com/install-pipx-ubuntu/
作者:[Sagar Sharma][a]
选题:[lkxed][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lkxed/
[1]: https://pypi.org:443/
[2]: https://itsfoss.com/externally-managed-environment/
[3]: https://itsfoss.com/content/images/2023/05/error--externally-managed-environment.png
[4]: https://itsfoss.com/install-pip-ubuntu/
[5]: https://itsfoss.com/add-directory-to-path-linux/
[6]: https://itsfoss.com/content/images/2023/05/install-pipx-in-ubuntu.png
[7]: https://itsfoss.com/content/images/2023/05/install-python-packages-in-isolation-using-pipx-in-ubuntu.png
[8]: https://itsfoss.com/content/images/2023/05/install-specific-version-of-python-package-in-ubuntu-using-pipx.png
[9]: https://itsfoss.com/content/images/2023/05/search-python-packages-in-Ubuntu.png
[10]: https://itsfoss.com/content/images/2023/05/upgrade-all-the-python-packages-at-once-in-ubuntu.png
[11]: https://itsfoss.com/content/images/2023/05/upgrade-specific-python-package-using-pipx-in-ubuntu.png
[12]: https://itsfoss.com/content/images/2023/05/remove-python-packages-using-pipx-in-ubuntu.png