根据公众号教程,打开 文件资源管理器,进入到 Python(Python3.9版本)安装目录中的 scripts 下,查看是否有 pip.exe, 如果用就可以使用 Python 自带的 pip 命令进行安装。
方式:Win+R后输入三个字母CMD,然后再执行pip install beautifulsoup4的命令
C:\Users\HHH>pip install beautifulsoup4
Collecting beautifulsoup4
Downloading beautifulsoup4-4.10.0-py3-none-any.whl (97 kB)
|████████████████████████████████| 97 kB 182 kB/s
Collecting soupsieve>1.2
Downloading soupsieve-2.3.1-py3-none-any.whl (37 kB)
Installing collected packages: soupsieve, beautifulsoup4
Successfully installed beautifulsoup4-4.10.0 soupsieve-2.3.1
WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available.
You should consider upgrading via the 'd:\python38\python.exe -m pip install --upgrade pip' command.
出现警告字样。
查询解决教程后,发现输入pip3 install --upgrade pip可以解决。输入后拒绝访问
C:\Users\HHH>pip3 install --upgrade pip
Requirement already satisfied: pip in d:\python38\lib\site-packages (21.1.1)
Collecting pip
Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
|████████████████████████████████| 1.7 MB 9.4 kB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.1.1
Uninstalling pip-21.1.1:
Successfully uninstalled pip-21.1.1
ERROR: Could not install packages due to an OSError: [WinError 5] 拒绝访问。: 'D:\\Python38\\~cripts\\pip3.exe'
Consider using the `--user` option or check the permissions.
再次寻找解决办法,执行命令:
python -m pip install -U --force-reinstall pip
Collecting pip
Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.3.1
Uninstalling pip-21.3.1:
Successfully uninstalled pip-21.3.1
Successfully installed pip-21.3.1
执行成功!!!但是我发现,这是装pip,和我的目的装beautifulsoup4大相径庭!!
后来居然发现很简单的方式,先下载beautifulsoup4的安装包。然后执行命令即可。
先进这个
再进这个
Index of /software/BeautifulSoup/bs4/download/4.0
下载你喜欢的压缩包
解压到python38文件夹下。
我的路径是:D:\Python38\beautifulsoup4-4.1.0
在cmd中,进入D:\Python38\beautifulsoup4-4.1.0>Python setup.py install
执行Python setup.py install显示
.......
byte-compiling D:\Python38\Lib\site-packages\bs4\tests\__init__.py to __init__.cpython-38.pyc
byte-compiling D:\Python38\Lib\site-packages\bs4\__init__.py to __init__.cpython-38.pyc
running install_egg_info
Writing D:\Python38\Lib\site-packages\beautifulsoup4-4.1.0-py3.8.egg-info
依然没有出现成功字样!
D:\Python38>pip install beautifulsoup4
没有执行成功,需要到路径下删除bs5相关文件
一共三个哦
然后再执行就成功了
D:\Python38>pip install beautifulsoup4
成功