安装pip的三种方法

1.get-pip.py安装

(官方)https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py

$wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py    # 运行安装脚本

注意:用哪个版本的 Python 运行安装脚本,pip 就被关联到哪个版本,如果是 Python3 则执行以下命令:

$ sudo python3 get-pip.py    # 运行安装脚本。

一般情况 pip 对应的是 Python 2.7,pip3 对应的是 Python 3.x
如果显示

root@66b6f8945ca1:/# python get-pip.py
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pip
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-p
y2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 1.8MB/s
Installing collected packages: pip
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
      Successfully uninstalled pip-18.1
Successfully installed pip-18.1

2.debian系列安装

     apt-get install -y pip        (python2.x就去安装pip2)
     apt-get install -y pip-python3       (python3.x就去安装pip3)

3.RHEL系列

 wget --no-check-certificate https://github.com/pypa/pip/archive/9.0.1.tar.gz
 tar -zvxf 9.0.1.tar.gz -C pip-9.0.1    # 解压文件
 cd pip-9.0.1
 python3 setup.py install
 pip install --upgrade pip       #升级pip(可选)

也就是说1.3方法都是二进制(源代码),但是我都去装了,都显示正确的信息,如1。但是无论是pip,还是pip3,还是pip -V,或者pip3 -V。都没反应,如同没装。不知道为何,记录一下,以后再试
为什么想要去用二进制装呢,因为我在制作docker的images,而apt install,需要先apt update,这样images会立刻增加200M。所以为了缩减,就想用二进制装一些必要的
现在有一个想法,是否需要建立软连接(ln s ),就如同二进制安装python时需要建立软连接。(20181019)

找到原因了,需要添加到环境里,第一种我有试了下,和之前返回成功信息一样,但这次信息里多了一些(我把默认改为python3.x)

root@853e19c0f418:/# python -V
Python 3.7.1rc2
root@853e19c0f418:/# python3 -V
Python 3.7.1rc2

root@3547dc8d3d33:/# python get-pip.py
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pip
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 1.9MB/s
Collecting wheel
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fc/e9/05316a1eec70c2bfc1c823a259546475bd7636ba6d27ec80575da523bc34/wheel-0.32.1-py2.py3-none-any.whl
Installing collected packages: pip, wheel
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
  The script wheel is installed in '/usr/python/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-18.1 wheel-0.32.1
root@3547dc8d3d33:/# pip
bash: pip: command not found
root@3547dc8d3d33:/# pip3
bash: pip3: command not found
root@3547dc8d3d33:/# pip list
bash: pip: command not found

显示成功但还是没反应,但是多了一条警告,说是

The script wheel is installed in '/usr/python/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

说是没有添加到path环境里,只是在 '/usr/python/bin',所以你在非其安装路径下是不可以执行pip相关命令
你如果去其安装路径执行pip命令,就可以了

root@3547dc8d3d33:/usr/python/bin# ls
2to3  2to3-3.7  easy_install-3.7  idle3  idle3.7  pip  pip3  pip3.7  pydoc3  pydoc3.7  python3  python3-config  python3.7  python3.7-config  python3.7m  python3.7m-config  pyvenv  pyvenv-3.7  wheel
root@3547dc8d3d33:/usr/python/bin# ./pip
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.
  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.
  help                        Show help for commands.
.........
.........

所以你只需要把其安装路径添加到path环境里,就可以全局调用(前两句(加入,生效))

root@3547dc8d3d33:/# echo 'export PATH=/usr/python/bin:$PATH' >>~/.bashrc
root@3547dc8d3d33:/# source ~/.bashrc
root@3547dc8d3d33:/# cd /
root@853e19c0f418:/# pip
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.
  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.
  help                        Show help for commands.
..............
root@853e19c0f418:/# pip3
Usage:
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
........................


root@853e19c0f418:/# pip -V
pip 18.1 from /usr/python/lib/python3.7/site-packages/pip (python 3.7)
root@853e19c0f418:/# pip3 -V
pip 18.1 from /usr/python/lib/python3.7/site-packages/pip (python 3.7)

pip和pip3都可以
所以第三种安装方法也应该需要这样才可以使用。(20181021)


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,117评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,963评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 107,897评论 0 240
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,805评论 0 203
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,208评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,535评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,797评论 2 311
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,493评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,215评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,477评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,988评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,325评论 2 252
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,971评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,055评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,807评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,544评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,455评论 2 266

推荐阅读更多精彩内容

  • 在 Ubuntu 上安装 TensorFlow 本指南将介绍如何在 Ubuntu 上安装 TensorFlow。虽...
    高山居士阅读 4,486评论 0 6
  • 网址 下载与安装 你可以使用我们提供的 Pip, Docker, Virtualenv, Anaconda 或 源...
    九七学姐阅读 4,648评论 3 11
  • 《向卑微的万物致敬》 秋风萧瑟起 万物归于沉寂 落叶扑向大地母亲的怀抱 冬雪又会覆盖湮没了一切 我行走在城市、荒郊...
    诗人李布阅读 381评论 0 2
  • 接着昨天的继续唠。 突然就想到这句话了,因为突然想起高考前的自己是多么努力,要每天记日记,在小本子上面写每天的收获...
    蝶未殇阅读 264评论 0 0
  • 每个人都有自己的生活态度,那都是自己成长的标志,生活态度是给自己生活的一种肯定,假若你对自己的生活没有一点点要求,...
    柒可可阅读 267评论 0 2