环境
Ubuntu 14.06
安装python2,版本为Python 2.7.12
安装python3,版本为Python 3.5.2
问题描述
由于使用python3需要beautifulsoup4和lxml模块。
使用
pip install beautifulsoup
pip install lxml
结果都安装到了python2中,没有正确安装到python3上。马上使用pip3
$sudo pip3 install beautifulsoup
zsh: command not found: pip3
告诉我们没有pip3。使用apt安装pip3,反馈如下
$ sudo apt-get install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pip is already the newest version (8.1.1-2ubuntu0.4).
什么情况,pip3已经安装了。但是就是定位不到pip3。
问题分析
由于共存了pytho2和python3导致。
解决方法
使用sudo python3 -m pip install --upgrade pip。
$sudo python3 -m pip install --upgrade pip
Collecting pip
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 43.9MB/s
Installing collected packages: pip
Found existing installation: pip 8.1.1
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-20.0.2
安装完成后,使用pip3 -v来验证是否安装成功。安装成功如下所示:
pip3 -v
Usage:
pip3 <command> [options]
使用sudo pip3 install beautifulsoup4,安装beautifulsoup4模块,如下所示:
sudo pip3 install beautifulsoup4
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting beautifulsoup4
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/cb/a1/c698cf319e9cfed6b17376281bd0efc6bfc8465698f54170ef60a485ab5d/beautifulsoup4-4.8.2-py3-none-any.whl (106 kB)
|████████████████████████████████| 106 kB 16.2 MB/s
Collecting soupsieve>=1.2
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/81/94/03c0f04471fc245d08d0a99f7946ac228ca98da4fa75796c507f61e688c2/soupsieve-1.9.5-py2.py3-none-any.whl (33 kB)
Installing collected packages: soupsieve, beautifulsoup4
Successfully installed beautifulsoup4-4.8.2 soupsieve-1.9.5
使用sudo pip3 install lxml,安装lxml模块,如下所示:
sudo pip3 install lxml
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting lxml
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/f2/e5/304cfec4e0abebb4a4e16f56129df792c81f1bcdbb1432d1a63f749f8b74/lxml-4.5.0-cp35-cp35m-manylinux1_x86_64.whl (5.7 MB)
|████████████████████████████████| 5.7 MB 901 kB/s
Installing collected packages: lxml
Successfully installed lxml-4.5.0
这样大功告成。