BeautifulSoup,from bs4 import BeautifulSoup遇到python版本错误的解决办法

问题由来

换了台Windows环境,准备搭建Python学习环境。
OS:Windows 10
Python:3.7,从官网下载安装包,安装目录"C:\Users\Username\AppData\Local\Programs\Python\Python37"
安装Python3.7正常,下载安装BeautifulSoup正常(从官网下载压缩包,解压到D盘根目录(D:\beautifulsoup4-4.7.1),运行Powershell:

d:\beautifulsoup4-4.7.1\python setup.py install

安装完成后,bs4库文件安装在如下路径:C:\Users\usename\AppData\Local\P
rograms\Python\Python37\Lib\site-packages\beautifulsoup4-4.7.1-py3.7.egg
显示一切正常。

d:\> python
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup
You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work.'<>'You need to convert the code, either by installing it (`python setup.py install`) or by running 2to3 (`2to3 -w bs4`).

解决办法

需要使用python自带的2to3脚本文件(2to3.py),转化bs4。
2to3.py在python安装目录的Tools/Scripts中(C:\Users\username\AppData\Local\Programs\Python\Python37\Tools\scripts),在powershell(或者命令提示符)中,进入2to3.py目录,运行如下命令:

C:\Users\username\AppData\Local\Programs\python\Python37\Tools\scripts>python 2to3.py -w C:\Users\steve\AppData\Local\P
rograms\Python\Python37\Lib\site-packages\beautifulsoup4-4.7.1-py3.7.egg\bs4
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

steventian72

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值