我已经从https://www.crummy.com/software/BeautifulSoup/bs4/download/4.5/下载了 beautifulsoup4-4.5.3.tar.gz并将其解压缩到我的 python 工作目录(这不是我的 python 安装目录) .
但是,当我跑步时
from bs4 import BeautifulSoup
在我的 IDLE 中弹出错误消息:
>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
from bs4 import BeautifulSoup
File "D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3\bs4\__init__.py",
line 53
'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`).'
^
SyntaxError: invalid syntax
我尝试了这些方法,但上面的错误消息不断弹出
- 在我的 IDLE 中打开 setup.py 并运行它(
=== RESTART: D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3\setup.py ===
在 IDLE 窗口中提供,但from bs4 import BeautifulSoup
没有工作) - 使用cmd进入D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3,运行
pip uninstall beautifulsoup4
然后运行pip install beautifulsoup4
;说明我已经成功在cmd行安装beautifulsoup4-4.5.3,但是IDLE中仍然出现错误消息后from bs4 import BeautifulSoup
- 使用cmd进入D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3,运行
pip3 uninstall beautifulsoup4
然后运行pip3 install beautifulsoup4
;和上面一样没用 - 运行
pip install bs4 --ignore-installed
,如上无用 - 运行
setup.py install
,如上无用 2to3 -w bs4
在 D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3 下的 cmd 行中运行,返回'2to3' is not recognized as an internal or external command,operable program or batch file.
我应该怎么办?
另外,pip show bs4
给了这个
`Metadata-Version: 1.1
Name: bs4
Version: 0.0.1
Summary: Screen-scraping library
Home-page: https://pypi.python.org/pypi/beautifulsoup4
Author: Leonard Richardson
Author-email: leonardr@segfault.org
License: MIT
Location: c:\users\myname\appdata\local\programs\python\python35-
32\lib\site-packages
Requires: beautifulsoup4
You are using pip version 7.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip'
command.`
在我的 C:\Users\myname\AppData\Local\Programs\Python\Python35-32\Lib\site-packages 目录下,可以看到三个 beautifulsoup 相关目录:beautifulsoup4-4.5.3.dist-info、bs4 和 bs4- 0.0.1-py3.5.egg-info,但from bs4 import BeautifulSoup
不断抛出错误信息