この記事では、Ubuntu20.04にpipをインストールする方法について説明します。まず、pipが実際に何であるかを明確にする必要があります。 Pip
Pythonのパッケージマネージャーです。通常、システムにPythonモジュールをインストールして管理するために使用されます。
Pythonが初めての場合でも、Pythonは高水準のオブジェクト指向プログラミング言語であり、長年にわたってますます人気が高まっています。 Pythonは、ソフトウェア開発、システム管理、科学および数値データ分析などで広く使用されています。
Python2またはPython3の両方をUbuntu20.04にインストールできます。ただし、Ubuntu20.04ではデフォルトバージョンはPython3です。何らかの理由でPython2とそのバージョンのpipが必要な場合でも、心配しないでください。このチュートリアルでも取り上げます。
PipはデフォルトではUbuntuにインストールされませんが、インストールは非常に迅速で簡単です。インストールから始めましょう。 Ubuntu 20.04にpipをインストールするのはかなり簡単な作業であり、10分以内に完了する必要があります。
まず、rootユーザーアカウントとして、またはsudo権限を持つユーザーとしてSSH経由でUbuntu20.04VPSにログインする必要があります。
ssh root@Server_IP_Address -p Port_Number
もちろん、Server_IP_Address
を置き換える必要があります およびPort_Number
実際のサーバーのIPアドレスとSSHポート番号を使用します。
次のコマンドを実行すると、インストールされているすべてのパッケージが更新およびアップグレードされます。
apt update && apt upgrade -y
サーバーを再起動して、最新の構成ファイルがすべて読み取られて使用されるようにすることもできます。
Python3用のpipをインストールする
サーバーにデフォルトのPythonバージョンがすでにインストールされていることを前提としています。 Python 3がサーバーにすでにインストールされているかどうかを確認するには、次のコマンドを使用します。
python3 -V
次の出力が得られるはずです:
root@ubuntu20:~# python3 -V Python 3.8.2
pipのインストールを続行する前に、pipがサーバーにすでにインストールされているかどうかを確認することをお勧めします。次のコマンドでこれを行うことができます:
pip3 -V
次の出力が得られた場合:
Command 'pip3' not found
これは、pip3がサーバーにインストールされていないことを意味します。次のコマンドを実行してpip3をインストールできます:
apt install python3-pip
上記のコマンドを実行すると、pipに必要なすべての依存関係がPiPとともにインストールされます。インストールが完了したら、次のコマンドを使用してインストールされたpipを検証できます。
pip3 --version
次のような出力が必要です。
root@ubuntu20:~# pip3 -V pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
Python 2用のPiPをインストールします(オプション)
何らかの理由でデフォルトのPython3バージョンの代わりにPython2を使用したい場合は、記事のこのセクションに従うことができます。
Python 2をインストールするには、次のコマンドを実行できます:
apt install python2
Python2用のPiPはUbuntu20.04リポジトリでは利用できないため、このステップではget-pip.py
を使用します。 脚本。次のコマンドを使用して、get-pip.py
をダウンロードします。 スクリプト:
curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py
これで、python2でスクリプトを実行して、Python2用のpipをインストールできます。
python2 get-pip.py
インストールが完了すると、次のコマンドでpipのバージョンを確認できます。
pip -V
次の出力が得られた場合:
root@ubuntu20:~# pip -V pip 20.1.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
次に、Python2用に正しいバージョンのpipがインストールされています。
pip3の使用方法
記事のこのステップでは、いくつかの便利な基本的なpipコマンドを紹介します。これでpipがインストールされたので、使用してみることができます。
pip3の基本的な構文は次のとおりです。
pip3 <command> [options]
次の例は、最も一般的に使用されるpip3コマンドです。
パッケージをインストールする場合:
pip3 install package_name
インストールされているすべてのパッケージを一覧表示できます:
pip3 list
または、パッケージを検索することもできます:
pip3 search package_name
何らかの理由でパッケージを削除/アンインストールする場合は、次のコマンドを使用できます。
pip3 uninstall package_name
ヘルプコマンドを実行すると、その他のオプションと使用例を見つけることができます:
pip3 --help
出力:
Usage: pip3 <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. config Manage local and global configuration. 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. debug Show information useful for debugging. 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 to a verbose appending log. --proxy Specify a proxy in the form [user:passwd@]proxy.server:port. --retries Maximum number of retries each connection should attempt (default 5 times). --timeout Set the socket timeout (default 15 seconds). --exists-action Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort. --trusted-host Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS. --cert Path to alternate CA bundle. --client-cert Path to SSL client certificate, a single file containing the private key and the certificate in PEM format. --cache-dir Store the cache data in. --no-cache-dir Disable the cache. --disable-pip-version-check --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. --no-color Suppress colored output --no-python-version-warning Silence deprecation warnings for upcoming unsupported Pythons.
また、特定のコマンドの詳細に関心がある場合は、次のコマンドを使用できます。
pip3 <command> --help
おめでとう!これで、ubuntu 20.04にpipが正常にインストールされ、pipの基本的なコマンドがいくつか学習されました。
Pythonとpipの管理は簡単ですが、Pythonアプリケーションを適切に実行することは苛立たしい経験になる可能性があります。マネージドPythonホスティングにより、安心してご利用いただけます。専門家のサポートチームが、必要なPythonアプリケーションをすぐに利用できるようにします。または、Ubuntu20.04にpipをインストールすることもできます。また、サーバーを保守し、VPSのコストに含まれるすべてのリクエストを実行することもできます。
共有したい提案や質問がありますか?コメント欄に残してください!共有ボタンを使用して、ソーシャルメディアでこのチュートリアルを共有することもできます。