GNU/Linux >> Linux の 問題 >  >> Ubuntu

UbuntuにPipをインストールする方法

Pipは、Pythonで記述されたソフトウェアパッケージをインストールできるコマンドラインツールです。 UbuntuにPipをインストールする方法と、PythonアプリケーションをインストールするためにPipを使用する方法を学びます。

TLDR

Ubuntu 20.04にPIPをインストールするには、ユニバースリポジトリを有効にしてから、次のようにpython3-pipパッケージをインストールする必要があります。

sudo add-apt-repository universe
sudo apt install python3-pip

Ubuntuにソフトウェアをインストールする方法はたくさんあります。ソフトウェアセンター、ダウンロードしたdebファイル、PPA、Snapパッケージ、Flatpak、AppImage、さらには古き良きソースコードからアプリケーションをインストールできます。

Ubuntuにパッケージをインストールする別の方法は次のとおりです。これはPIPと呼ばれ、Pythonベースのアプリケーションをインストールするために使用できます。

ピップとは何ですか?

Pipは「PipInstallsPackages」の略です。 Pipは、コマンドラインベースのパッケージ管理システムです。 Python言語で記述されたソフトウェアのインストールと管理に使用されます。

pipを使用して、Python Package Index(PyPI)にリストされているパッケージをインストールできます。

ソフトウェア開発者は、pipを使用して、独自のPythonプロジェクト用のさまざまなPythonモジュールとパッケージをインストールできます。

エンドユーザーとして、Pythonを使用して開発され、pipを使用して簡単にインストールできる一部のアプリケーションをインストールするためにpipが必要になる場合があります。そのような例の1つは、ストレスです。 pipで簡単にインストールできるターミナルアプリケーション。

Ubuntuやその他のUbuntuベースのディストリビューションにpipをインストールする方法を見てみましょう。

Ubuntu、Linux Mint、その他のUbuntuベースのディストリビューションにpipをインストールする方法

Ubuntu18.04にはデフォルトでPython2とPython3の両方がインストールされているため、Pythonのバージョンごとに2つのPIPのバリエーションがあります。デフォルトでは、PipはPython2バージョンを指します。 Python3のPipはpip3と呼ばれます。

Python 2は非推奨であり、Ubuntu20.04以降のバージョンでは使用できません。インストールできるのはPIP3のみです。

まず、Python3がUbuntuにインストールされていることを確認します。これを確認するには、次のコマンドを使用します:

python3 --version

Python 3.6.6のような番号が表示されている場合は、Python3がLinuxシステムにインストールされています。

これで、以下のコマンドを使用してpip3をインストールできます。

sudo apt install python3-pip

次のコマンドを使用して、pip3が正しくインストールされていることを確認する必要があります。

pip3 --version

次のような番号が表示されます:

pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

これは、pip3がシステムに正常にインストールされたことを意味します。

非推奨のPython2バージョンのpipをインストールします(Ubuntu 18.04のみ)

何らかの理由で本当にpip2が必要な場合は、次のことを行う必要があります。

まず、Python2がインストールされていることを確認します。 Ubuntuでは、以下のコマンドを使用して確認します。

python2 --version

エラーがなく、Pythonのバージョンを示す有効な出力がある場合は、Python2がインストールされています。これで、次のコマンドを使用してPython2のpipをインストールできます。

sudo apt install python-pip

pipと他の多くの依存関係をインストールします。インストールしたら、pipが正しくインストールされていることを確認します。

pip --version

次のようなバージョン番号が表示されます:

pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

これは、Ubuntuにpipを正常にインストールしたことを意味します。

おすすめの記事:

LinuxおよびUnixシステムでのPython環境のセットアップ

LinuxとUnixでPython2とPython3の両方の仮想環境をセットアップします。

pipコマンドの使用方法

pipをインストールしたので、基本的なpipコマンドのいくつかを簡単に見てみましょう。これらのコマンドは、Pythonパッケージの検索、インストール、および削除にpipコマンドを使用するのに役立ちます。

pipを使用してパッケージをインストールする

PIPを使用してパッケージをインストールする方法は2つあります。現在ログインしているユーザー用にインストールするか、システム全体にインストールします。

–userオプションを使用すると、ログインしたユーザー、つまりsudoアクセスを必要とせずにパッケージがインストールされます。インストールされたPythonソフトウェアは、あなたとあなたのシステム上の他のユーザー(もしあれば)だけが利用できます。

pip3 install --user python_package_name

–userオプションを削除すると、パッケージはシステム全体にインストールされ、システム上のすべてのユーザーが利用できるようになります。この場合、sudoアクセスが必要になります。

sudo pip3 install python_package_name

PIPは、デフォルトではタブ補完をサポートしていません。したがって、インストールする正確なパッケージ名を知っている必要があります。どうやってそれを手に入れますか?次のセクションでそれをお見せします。

pipを使用してパッケージを検索する

Pythonでパッケージを検索するには パッケージインデックスでは、次のpipコマンドを使用できます:

pip3 search search_string

たとえば、「stress」で検索すると、名前または説明に「stress」という文字列が含まれるすべてのパッケージが表示されます。

pip3 search stress
stress (1.0.0)                - A trivial utility for consuming system resources.
s-tui (0.8.2)                 - Stress Terminal UI stress test and monitoring tool
stressypy (0.0.12)            - A simple program for calling stress and/or stress-ng from python
fuzzing (0.3.2)               - Tools for stress testing applications.
stressant (0.4.1)             - Simple stress-test tool
stressberry (0.1.7)           - Stress tests for the Raspberry Pi
mobbage (0.2)                 - A HTTP stress test and benchmark tool
stresser (0.2.1)              - A large-scale stress testing framework.
cyanide (1.3.0)               - Celery stress testing and integration test support.
pysle (1.5.7)                 - An interface to ISLEX, a pronunciation dictionary with stress markings.
ggf (0.3.2)                   - global geometric factors and corresponding stresses of the optical stretcher
pathod (0.17)                 - A pathological HTTP/S daemon for testing and stressing clients.
MatPy (1.0)                   - A toolbox for intelligent material design, and automatic yield stress determination
netblow (0.1.2)               - Vendor agnostic network testing framework to stress network failures
russtress (0.1.3)             - Package that helps you to put lexical stress in russian text
switchy (0.1.0a1)             - A fast FreeSWITCH control library purpose-built on traffic theory and stress testing.
nx4_selenium_test (0.1)       - Provides a Python class and apps which monitor      and/or stress-test the NoMachine NX4 web interface
physical_dualism (1.0.0)      - Python library that approximates the natural frequency from stress via physical dualism, and vice versa.
fsm_effective_stress (1.0.0)  - Python library that uses the rheological-dynamical analogy (RDA) to compute damage and effective buckling stress in prismatic shell structures.
processpathway (0.3.11)       - A nifty little toolkit to create stress-free, frustrationless image processing pathways from your webcam for computer vision experiments. Or observing your cat.

pip経由でインストールされたパッケージを削除する

pipを介してインストールされたPythonパッケージを削除する場合は、削除オプションを使用できます。

pip3 uninstall installed_package_name

Ubuntu 18.04でpip2を使用している場合は、上記のコマンドでpip3の代わりにpipを使用できます。

この簡単なヒントが、Ubuntuにpipをインストールするのに役立つことを願っています。ご質問やご提案がございましたら、下のコメントセクションでお知らせください。



Ubuntu
  1. Ubuntu16.04にPipをインストールする方法

  2. Ubuntu18.04にpipをインストールする方法

  3. Ubuntu20.04にpipをインストールする方法

  1. Ubuntu18.04にPipをインストールする方法

  2. Ubuntu20.04にRをインストールする方法

  3. Ubuntu18.04にGoをインストールする方法

  1. Ubuntu18.04にRをインストールする方法

  2. Ubuntu20.04にPythonPipをインストールする方法

  3. UbuntuにPipをインストールする方法