Pythonパッケージ管理ツールpipのインストールと使用
8132 ワード
pip取り付け使用詳細:http://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa pythonパッケージ:https://pypi.python.org/pypi
pythonにpythonモジュールをインストールするには、三つの方法があります。
setuptoolsをインストールして、easuryを使います。install*.eggコマンドでインストールします。一般的にpython setup.py installがインストールしたモジュールで、pythonモジュールをインストールすることができます。
pipコマンドはRedHatの中のyumに似ています。インストールします。 Python カバンはとても便利です
おすすめ:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
python3, python3 pip3 , pip3。
pip3 python3 bin
アップグレードpip 3
通常、PCにpython 2.xをインストールしてもpython 3.xをインストールすれば、2つのpipがあるはずです。一つはpip 2、もう一つはpip 3です。はい、もう一つは2もないし、3もあるpipがあります。普通はpip=pip 2です。
たまに私達はpipを使ってものをインストールして私達のpipのバージョンが低すぎることをヒントすることができて、私達が進級することを提案して、普通の情況の下で私達がpip 3を使う時もちろん下の命令で進級したいです。しかし、そうすれば、正しい姿勢ではないようです。実はこれは論理的な間違いです。正しい答えを見たら、どこが間違っているのか分かります。
正しいアップグレードpip 3は以下の通りです。pip 3 install-ugrade pip
国内の鏡像をpython pipに使用させる
清華:https://pypi.tuna.tsinghua.edu.cn/simple アリ雲:http://mirrors.aliyun.com/pypi/simple/ 中国科学技術大学https://pypi.mirrors.ustc.edu.cn/simple/ 華中理工大学:http://pypi.hustunique.com/ 山東理工大学:http://pypi.sdutlinux.org/ 豆の花びら:http://pypi.douban.com/simple/
注意:新版のuuntuはhttpsソースの使用を要求しています。
例えば、pip install-ihttps://pypi.tuna.tsinghua.edu.cn/simple pyspider このように清华侧のミラーからpyspiderライブラリをインストールします。
豆板源を使ってrobobrowserをインストールします。pip install robobroowser-ihttp://pypi.douban.com/simple/
内容は以下の通りです
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
windowsの下で、直接userディレクトリの中で1つのpipディレクトリを創立して、更にファイルのpip.iniを新築します。(例えば、C:\Users\WQP\pip\pip.ini)コンテンツは同じです。1.pipダウンロードインストール
ダウンロード
# wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate
またはpype公式サイト( https://pypi.python.org/pypi )直接ソースのインストールをダウンロードするpip取り付け
# tar -xzvf pip-1.5.4.tar.gz
# cd pip-1.5.4
# python setup.py install
2.pip使用詳細
pip使用ヘルプ
root@kali:~$ pip -h
Usage:
pip [options]
Commands:
install .
download .
uninstall .
freeze .
list .
show .
check .
search PyPI .
wheel Build wheels from your requirements.
hash .
completion 。
help .
General Options:
-h, --help .
--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
-v, --verbose , 3
-V, --version
-q, --quiet , 。
--log Path to a verbose appending log.
--proxy 。 : [user:passwd@]proxy.server:port.
--retries Maximum number of retries each connection should attempt (default 5 times).
--timeout socket 。(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 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
Don't periodically check PyPI to determine whether a new version of pip is available for
download. Implied with --no-index.
pipの中のあるコマンドのヘルプを見たいなら、例えばpip list、使用できます。pip list-hroot@kali:~$ pip list -h
Usage:
pip list [options]
Description:
List installed packages, including editables.
Packages are listed in a case-insensitive sorted order.
List Options:
-o, --outdated List outdated packages
-u, --uptodate List uptodate packages
-e, --editable List editable projects.
-l, --local If in a virtualenv that has global access, do not list globally-installed packages.
--user Only output packages installed in user-site.
--pre Include pre-release and development versions. By default, pip only finds stable versions.
--format Select the output format among: legacy (default), columns, freeze or json.
--not-required List packages that are not dependencies of installed packages.
Package Index Options (including deprecated options):
-i, --index-url Base URL of Python Package Index (default https://pypi.python.org/simple). This should
point to a repository compliant with PEP 503 (the simple repository API) or a local
directory laid out in the same format.
--extra-index-url Extra URLs of package indexes to use in addition to --index-url. Should follow the same
rules as --index-url.
--no-index Ignore package index (only looking at --find-links URLs instead).
-f, --find-links If a url or path to an html file, then parse for links to archives. If a local path or
file:// url that's a directory, then look for archives in the directory listing.
--process-dependency-links Enable the processing of dependency links.
例: pip list--out data 更新が必要なpythonパッケージを確認します。pipを使ってカバンを取り付けます。
# pip install SomePackage
[...]
Successfully installed SomePackage
pipを使ってインストールされたカバンを確認します。
# pip show --files SomePackage
Name:SomePackage
Version:1.0
Location:/my/env/lib/pythonx.x/site-packages
Files:
../somepackage/__init__.py
[...]
pipを使ってどのカバンを検査しますか?更新が必要です。
# pip list --outdated
SomePackage (Current: 1.0 Latest: 2.0)
使用 pipアップグレードパッケージ
# pip install --upgrade SomePackage
[...]
Foundexistinginstallation:SomePackage1.0
UninstallingSomePackage:
SuccessfullyuninstalledSomePackage
Runningsetup.pyinstallforSomePackage
SuccessfullyinstalledSomePackage
パッケージをpipでアンインストールする
$ pip uninstall SomePackage
Uninstalling SomePackage:
/my/env/lib/pythonx.x/site-packages/somepackage
Proceed (y/n)? y
Successfully uninstalled SomePackage
3.pip使用例
でインストールします。
redis
# pip install redis
redis
# pip uninstall redis
Uninstalling redis:
/usr/lib/python2.6/site-packages/redis-2.9.1-py2.6.egg-info
..... ....
Proceed (y/n)? y
Successfully uninstalled redis
pip list --outdate
よくあるエラー:ImportError No module named setuptools。インストールされていないと説明します setuptoolsモジュール、直接ダウンロードしてインストールすればいいです。