Linux下pip變爲用pip3使用python3解釋器,查看pip3。輸入python默認用python3解釋器

pip變爲用pip3使用python3解釋器,查看pip3。
能用代碼說明一切就絕不BB。

hellopython@ubuntu:/usr/bin$ pip3 freeze

Command 'pip3' not found, but can be installed with:

sudo apt install python3-pip

hellopython@ubuntu:/usr/bin$ sudo apt install python3-pip
hellopython@ubuntu:/usr/bin$ pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
hellopython@ubuntu:/usr/bin$ pip3 install selenium
Successfully installed selenium-3.141.0 urllib3-1.25.7

hellopython@ubuntu:/usr/bin$ pip3 show selenium
Name: selenium
Version: 3.141.0
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: /home/hellopython/.local/lib/python3.6/site-packages
Requires: urllib3

hellopython@ubuntu:/usr/bin$ whereis python3
python3: /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3 /usr/bin/python3.6-config /usr/bin/python3.6m-config /usr/lib/python3.6 /usr/lib/python3 /usr/lib/python3.7 /usr/lib/python3.8 /etc/python3.6 /etc/python3 /usr/local/lib/python3.6 /usr/include/python3.6 /usr/include/python3.6m /usr/share/python3 /usr/share/man/man1/python3.1.gz

hellopython@ubuntu:/usr/bin$ pip3 freeze
apturl==0.5.2
selenium==3.141.0
.......

pip3安裝的模塊是用python3解釋器運行,pip就默認用python2解釋器。

輸入python默認用python3解釋器:
https://blog.csdn.net/weixin_43296326/article/details/88671133

我建議按系統來的就好,沒必要做下面修改,因爲只要用python3或者pip3 就能使用python3解釋器,否則就能用python2解釋器,萬一真用得上python2呢。如果你喜歡折騰,不要python2,全默認python3就按以下步驟來做吧:

hellopython@ubuntu:~$ sudo rm -rf /usr/bin/python
(輸入python命令就會調用該位置的命令,從而使用python2解釋器。所以要刪除原本的python連接)
[sudo] password for hellopython: 
hellopython@ubuntu:~$ python

Command 'python' not found, but can be installed with:

sudo apt install python3       
sudo apt install python        
sudo apt install python-minimal

You also have python3 installed, you can run 'python3' instead.
hellopython@ubuntu:~$ pip install selenium
bash: /home/hellopython/.local/bin/pip: /usr/bin/python: bad interpreter: No such file or directory
hellopython@ubuntu:/usr/local/bin$ sudo ln -s /usr/local/bin/python3 /usr/bin/python

**(爲 /usr/local/bin/python3 創建軟鏈接到 /usr/bin/python,以後輸入pyhton命令使用/usr/bin/python就會調用/usr/local/bin/python3)**

hellopython@ubuntu:~$ python

Command 'python' not found。。。。。
(無效後重新刪除鏈接如下)

hellopython@ubuntu:/usr/local/bin$ sudo rm -rf /usr/bin/python
hellopython@ubuntu:~$ which python
/usr/bin/python

hellopython@ubuntu:~$ which python3
/usr/bin/python3

hellopython@ubuntu:/usr/local/bin$ sudo ln -s /usr/bin/python3 /usr/bin/python
hellopython@ubuntu:/usr/local/bin$ python
Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 


hellopython@ubuntu:~/.local/bin$ pip2 freeze
Traceback (most recent call last):
  File "/home/hellopython/.local/bin/pip2", line 7, in <module>
    from pip._internal.main import main
ModuleNotFoundError: No module named 'pip._internal'
hellopython@ubuntu:~/.local/bin$ pip3 freeze
apturl==0.5.2
asn1crypto==0.24.0
Brlapi==0.6.6
certifi==2018.1.18
chardet==3.0.4
.......
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章