mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-21 02:10:11 +08:00
Merge pull request #29495 from lkxed/20230530-0-Install-and-Use-pipx-in-Linux
[手动选题][tech]: 20230530.0 ⭐️⭐️ Install and Use pipx in Linux.md
This commit is contained in:
commit
854d3e5d82
184
sources/tech/20230530.0 ⭐️⭐️ Install and Use pipx in Linux.md
Normal file
184
sources/tech/20230530.0 ⭐️⭐️ Install and Use pipx in Linux.md
Normal 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: " "
|
||||
[#]: 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
|
Loading…
Reference in New Issue
Block a user