このチュートリアルでは、Ubuntu18.04VPSにpipをインストールする方法を示します。
Pipは、Pythonで記述されたパッケージをインストールおよび管理するために使用できるパッケージ管理システムです。 Pythonは、Web開発、ソフトウェア開発、システム管理、科学的および数値データ分析などを実行できるプログラミング言語です。 Python Package Index(PyPI)は、Python用の何千ものサードパーティモジュールをホストしており、pipパッケージマネージャーを使用してこれらのモジュールのいずれかをインストールできます。 Ubuntu 18.04へのPipのインストールは非常に簡単な作業であり、手順に注意深く従えば、わずか数分でUbuntu18.04VPSにpipがインストールされます。インストールを始めましょう。
前提条件:
- Ubuntu 18.04 VPS
- rootアカウントまたはsudo権限を持つユーザーへのアクセス。
ステップ1:サーバーに接続する
rootユーザーとしてSSH経由でサーバーに接続するには、次のコマンドを使用します。
ssh root@IP_ADDRESS -p PORT_NUMBER
「IP_ADDRESS」と「PORT_NUMBER」を実際のサーバーのIPアドレスとSSHポート番号に置き換えます。必要に応じて、「root」という単語の代わりに管理者アカウントのユーザー名を使用できます。
ログインしたら、次のコマンドを実行して、サーバーが最新であることを確認します。
apt update apt upgrade
ステップ2:Python3用のpipをインストールする
Python 3は、Ubuntu18.04に付属するデフォルトバージョンです。 Python 3のpipがサーバーにすでにインストールされているかどうかを確認するには、次のコマンドを実行します。
pip3 -V
pip3がインストールされていない場合、次の出力が得られます。
Command 'pip3' not found, but can be installed with: apt install python-pip3
これで、次のコマンドを実行してpip3をインストールできます。
apt install python-pip3
インストールが完了したら、pip3が正常にインストールされたかどうかをもう一度確認できます。
pip3 -V
pip3が正常にインストールされると、画面に次の出力が表示されます。
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
ステップ3:Python 2用のpipをインストールする(オプション)
Ubuntu18.04サーバーでデフォルトのPython3バージョンの代わりにPython2を使用する場合は、代わりに次の手順に従うことができます。
まず、pip(Python 2の場合)がサーバーにインストールされているかどうかを確認します。
pip -V
pipがインストールされていない場合は、次の出力が得られます。
Command 'pip' not found, but can be installed with: apt install python-pip
サーバーにpipとPython2をインストールするには、次のコマンドを実行します。
apt install python-pip
インストールが完了したら、次のコマンドで確認できます。
pip -V
次の出力が画面に表示されます。
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
ステップ4:基本的なpip3コマンド
サーバーにpip3が正常にインストールされたので、いくつかの基本事項を確認して、pip3の使用方法を説明します。
pip3の基本的な構文は次のとおりです。
pip3 <command> [options]
ここに、pip3の使用を開始するのに役立ついくつかの便利なコマンドがあります。
パッケージを検索するには、次のコマンドを実行します。
pip3 search package_name
パッケージをインストールするには:
pip3 install package_name
インストールされているすべてのパッケージを一覧表示するには:
pip3 list
パッケージをアンインストールするには:
pip3 uninstall package_name
その他のpip3オプションと使用例については、次のコマンドを実行できます。
pip3 --help Usage: pip <command> [options] Commands: install Install packages. download Download packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. check Verify installed packages have compatible dependencies. search Search PyPI for packages. wheel Build wheels from your requirements. hash Compute hashes of package archives. completion A helper command used for command completion. help Show help for commands. General Options: -h, --help Show help. --isolated Run pip in an isolated mode, ignoring environment variables and user configuration. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels). --log <path> Path to a verbose appending log. --proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port. --retries <retries> Maximum number of retries each connection should attempt (default 5 times). --timeout <sec> Set the socket timeout (default 15 seconds). --exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort. --trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS. --cert <path> Path to alternate CA bundle. --client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format. --cache-dir <dir> Store the cache data in <dir>. --no-cache-dir Disable the cache. --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
また、特定のコマンドに関する詳細情報を取得したい場合は、次のコマンドを使用できます。
pip3 <command> --help
おめでとうございます–これでPipのインスタンスがインストールされ、その使用方法について詳しく知ることができました。
もちろん、Python VPSホスティングサービスのいずれかを使用している場合は、Ubuntu 18.04にpipをインストールする必要はありません。その場合は、専門のLinux管理者にUbuntu18.04にpipをインストールするよう依頼するだけです。彼らは24時間年中無休で利用可能であり、あなたの要求をすぐに処理します。また、Ubuntu20.04にpipをインストールする方法に関する投稿を公開しました。
PS。 Ubuntu 18.04にpipをインストールする方法に関するこの投稿が気に入った場合は、下のボタンを使用してソーシャルネットワーク上の友達と共有するか、コメントセクションに返信を残してください。ありがとう。
新しいバージョンへのリンクは次のとおりです。Ubuntu20.04にpipをインストールする方法。