• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Python2和python3同时存在时,用pip把python2安装库文件

武飞扬头像
akaiziyou
帮助1

环境为 Linux Ubuntu20.04

1. 装curl,用于下载python2 的pip

$ sudo apt install curl

2. 给python2 安装pip

  1.  
    $ cd /usr/local/lib
  2.  
    $ sudo curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
  3.  
    $ sudo python get-pip.py
  4.  
     
  5.  
    # 查看pip版本
  6.  
     
  7.  
    $ pip -V
  8.  
    pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
  9.  
     
  10.  
     
  11.  
    # 从上面的输出确认jenkinsapi的位置,在python2.7下面

3. 用pip给python2安装库文件,以jenkinsapi为例

  1.  
    $ sudo python2 -m pip install jenkinsapi
  2.  
     
  3.  
    # 验证jenkinsapi已经安装给了python2
  4.  
     
  5.  
    $ python -V
  6.  
    Python 2.7.18
  7.  
    $ python -c "import jenkinsapi"
  8.  
     
  9.  
    # 没报错,jenkinsapi的python库已经安装到python2

整个过程截屏如下以供参考:

  1.  
    $ sudo apt install curl
  2.  
    Reading package lists... Done
  3.  
    Building dependency tree
  4.  
    Reading state information... Done
  5.  
    The following packages were automatically installed and are no longer required:
  6.  
    libfprint-2-tod1 libfwupdplugin1 libllvm9 linux-headers-5.4.0-26 linux-headers-5.4.0-26-generic linux-image-5.4.0-26-generic
  7.  
    linux-modules-5.4.0-26-generic linux-modules-extra-5.4.0-26-generic
  8.  
    Use 'sudo apt autoremove' to remove them.
  9.  
    The following NEW packages will be installed:
  10.  
    curl
  11.  
    0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded.
  12.  
    Need to get 161 kB of archives.
  13.  
    After this operation, 412 kB of additional disk space will be used.
  14.  
    Get:1 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 curl amd64 7.68.0-1ubuntu2.7 [161 kB]
  15.  
    Fetched 161 kB in 2s (81.2 kB/s)
  16.  
    Selecting previously unselected package curl.
  17.  
    (Reading database ... 274929 files and directories currently installed.)
  18.  
    Preparing to unpack .../curl_7.68.0-1ubuntu2.7_amd64.deb ...
  19.  
    Unpacking curl (7.68.0-1ubuntu2.7) ...
  20.  
    Setting up curl (7.68.0-1ubuntu2.7) ...
  21.  
    Processing triggers for man-db (2.9.1-1) ...
  22.  
     
  23.  
     
  24.  
    $ sudo curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
  25.  
    % Total % Received % Xferd Average Speed Time Time Time Current
  26.  
    Dload Upload Total Spent Left Speed
  27.  
    100 1863k 100 1863k 0 0 2376k 0 --:--:-- --:--:-- --:--:-- 2373k
  28.  
     
  29.  
     
  30.  
    $ sudo python get-pip.py
  31.  
    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
  32.  
    Collecting pip<21.0
  33.  
    Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
  34.  
    |████████████████████████████████| 1.5 MB 666 kB/s
  35.  
    Collecting setuptools<45
  36.  
    Downloading setuptools-44.1.1-py2.py3-none-any.whl (583 kB)
  37.  
    |████████████████████████████████| 583 kB 47.9 MB/s
  38.  
    Collecting wheel
  39.  
    Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)
  40.  
    Installing collected packages: pip, setuptools, wheel
  41.  
    Successfully installed pip-20.3.4 setuptools-44.1.1 wheel-0.37.1
  42.  
     
  43.  
     
  44.  
    $ sudo python2 -m pip install jenkinsapi
  45.  
    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
  46.  
    Collecting jenkinsapi
  47.  
    Using cached jenkinsapi-0.3.11-py2.py3-none-any.whl (135 kB)
  48.  
    Collecting pytz>=2014.4
  49.  
    Downloading pytz-2022.1-py2.py3-none-any.whl (503 kB)
  50.  
    |████████████████████████████████| 503 kB 577 kB/s
  51.  
    Collecting six>=1.10.0
  52.  
    Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
  53.  
    Collecting requests>=2.3.0
  54.  
    Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
  55.  
    |████████████████████████████████| 63 kB 3.2 MB/s
  56.  
    Collecting idna<3,>=2.5; python_version < "3"
  57.  
    Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
  58.  
    |████████████████████████████████| 58 kB 9.5 MB/s
  59.  
    Collecting certifi>=2017.4.17
  60.  
    Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
  61.  
    |████████████████████████████████| 149 kB 15.9 MB/s
  62.  
    Collecting chardet<5,>=3.0.2; python_version < "3"
  63.  
    Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
  64.  
    |████████████████████████████████| 178 kB 15.3 MB/s
  65.  
    Collecting urllib3<1.27,>=1.21.1
  66.  
    Downloading urllib3-1.26.9-py2.py3-none-any.whl (138 kB)
  67.  
    |████████████████████████████████| 138 kB 15.2 MB/s
  68.  
    Installing collected packages: pytz, six, idna, certifi, chardet, urllib3, requests, jenkinsapi
  69.  
    Successfully installed certifi-2021.10.8 chardet-4.0.0 idna-2.10 jenkinsapi-0.3.11 pytz-2022.1 requests-2.27.1 six-1.16.0 urllib3-1.26.9
  70.  
     
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgcggbe
系列文章
更多 icon
同类精品
更多 icon
继续加载