Ubuntu如何安装及使用Python3-pip
本文小编为大家详细介绍“Ubuntu如何安装及使用Python3-pip”,内容详细,步骤清晰,细节处理妥当,希望这篇“Ubuntu如何安装及使用Python3-pip”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
创新互联专注于城中企业网站建设,成都响应式网站建设公司,商城网站建设。城中网站建设公司,为城中等地区提供建站服务。全流程按需设计网站,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务
需要安装额外的模块比如requests模块来使用已有的功能,而要安装和管理Python的模块,使用pip无疑是一个方便快捷的工具:
pip 是一个现代的,通用的 Python 包管理工具。提供了对 Python 包的查找、下载、安装、卸载的功能。
在Ubuntu 16.04上面安装Python3版本的pip工具很方便,直接sudo apt install python3-pip就可以了:
daweibro@Workstation:~$ sudo apt install python3-pipReading package lists... DoneBuilding dependency treeReading state information... DoneThe following additional packages will be installed:libpython3-dev libpython3.5 libpython3.5-dev libpython3.5-minimallibpython3.5-stdlib python-pip-whl python3-dev python3-setuptoolspython3-wheel python3.5 python3.5-dev python3.5-minimalSuggested packages:python-setuptools-doc python3.5-venv python3.5-docThe following NEW packages will be installed:libpython3-dev libpython3.5-dev python-pip-whl python3-dev python3-pippython3-setuptools python3-wheel python3.5-devThe following packages will be upgraded:libpython3.5 libpython3.5-minimal libpython3.5-stdlib python3.5python3.5-minimal5 upgraded, 8 newly installed, 0 to remove and 42 not upgraded.Need to get 43.5 MB/44.9 MB of archives.After this operation, 56.4 MB of additional disk space will be used.Do you want to continue? [Y/n]
按Y安装完成后,查看pip的版本,发现是对应Ubuntu系统自带的Python 3.5:
daweibro@Workstation:~$ pip3 -Vpip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
这时候如果使用pip install命令安装Python模块,应该是关联到默认的 Python 3.5 版本。创新互联使用 pip3 install requests 命令安装好以后,发现安装的 requests 版本是2.20.1:
daweibro@Workstation:~$ pip3 list | grep requestsrequests (2.20.1)
而创新互联正在学习使用的是Python3.6,系统自带的requests版本仍然是2.9.1版本:
daweibro@Workstation:~$ python3.6 -m pip list | grep requestsrequests (2.9.1)
第一个解决办法,是改变Ubuntu的默认Python3版本,让Python3版本直接默认运行Python 3.6,这种方式只需要修改一次,不过有很少的可能会导致Ubuntu系统出错。另外一种方法,是保留系统默认的Python版本不变,而是使用python3.6 -m pip install命令给Python 3.6安装需要的模块,使用python3.6 -m pip install --upgrade命令给Python 3.6升级对应的模块。这种方法虽然麻烦一点,但是不会和系统产生任何冲突,适用于创新互联这样的编程小白。
daweibro@Workstation:~$ python3.6 -m pip install --upgrade requestsCollecting requestsUsing cached https://files.pythonhosted.org/packages/ff/17/5cbb026005115301a8fb2f9b0e3e8d32313142fe8b617070e7baad20554f/requests-2.20.1-py2.py3-none-any.whlCollecting idna<2.8,>=2.5 (from requests)Using cached https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whlCollecting urllib3<1.25,>=1.21.1 (from requests)Using cached https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whlCollecting chardet<3.1.0,>=3.0.2 (from requests)Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whlCollecting certifi>=2017.4.17 (from requests)Using cached https://files.pythonhosted.org/packages/56/9d/1d02dd80bc4cd955f98980f28c5ee2200e1209292d5f9e9cc8d030d18655/certifi-2018.10.15-py2.py3-none-any.whlInstalling collected packages: idna, urllib3, chardet, certifi, requestsSuccessfully installed certifi-2018.10.15 chardet-3.0.4 idna-2.7 requests-2.20.1 urllib3-1.24.1You are using pip version 8.1.1, however version 18.1 is available.You should consider upgrading via the 'pip install --upgrade pip' command.daweibro@Workstation:~$ python3.6 -m pip list | grep requestsrequests (2.20.1)You are using pip version 8.1.1, however version 18.1 is available.You should consider upgrading via the 'pip install --upgrade pip' command.
现在可以在Ubuntu 16.04下面使用Python 3.6和最新的requests模块了。
读到这里,这篇“Ubuntu如何安装及使用Python3-pip”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注创新互联行业资讯频道。
网站名称:Ubuntu如何安装及使用Python3-pip
链接URL:http://myzitong.com/article/jhpies.html