您好,登錄后才能下訂單哦!
本文小編為大家詳細介紹“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”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。