本文基于Ubuntu20.04操作系统,相关命令是该系统特有,请注意甄别。
今天要给Python安装一个外部的模块,于是按照老师的方法,使用pip
命令进行安装,结果一运行安装命令就出现了如下报错:
Command 'pip' not found, but there are 18 similar ones.
在网上找到的答案:
The different versions of Python are not surprising. WSL is, effectively, an ultra-lightweight virtual machine. Your Windows python installation is entirely independent of the WSL python installation.
Python has two widely used major versions, Python 2 and Python 3. The command python
runs some minor version of Python 2, while the command python3
runs some minor version of Python 3. Below is my console output.
lawruble@Balrog:~/scratch$ python --version
Python 2.7.18
lawruble@Balrog:~/scratch$ python3 --version
Python 3.8.5
Pip is the python installation manager, and has the same major versions as Python. The command pip
runs the Python 2 version of pip, while pip3
runs the Python 3 version of pip.
It's better practice to use python3 -m pip
over pip3
, it helps ensure that you're using the version of pip associated with the version of python you expect to run.
他的意思大概就是说要看一下自己使用的是什么版本的Python,如果用的是Python2的话,就可以使用pip
命令。但是如果你安装的是Python3的话,就要使用pip3
这个命令来安装。
看来我的情况跟他描述是一样的,我的确是系统默认安装的python3.8。然后我就试一试pip3,结果还是报错:
Command 'pip3' not found, but can be installed with:
sudo apt install python3-pip
原来我报错的原因是我根本就还没有安装pip3
呢,不过好在它提示我可以安装,于是我就使用下面的命令安装了:
sudo apt install python3-pip
再次运行pip3
安装模块,一切正常了。
Python小白之路,幼稚的问题可真多!
文章评论