Har*_*rry 5 windows installation beautifulsoup python-2to3 python-3.x
我已经从https://www.crummy.com/software/BeautifulSoup/bs4/download/4.5/下载了 beautifulsoup4-4.5.3.tar.gz并将其解压缩到我的 python 工作目录(这不是我的 python 安装目录) .
然而,当我跑
from bs4 import BeautifulSoup
Run Code Online (Sandbox Code Playgroud)
在我的 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
Run Code Online (Sandbox Code Playgroud)
我尝试了这些方法,但上面的错误提示不断弹出
=== RESTART: D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3\setup.py ===在 IDLE 窗口中给出,但from bs4 import BeautifulSoup没有用)pip uninstall beautifulsoup4后运行pip install beautifulsoup4;显示我在cmd行成功安装了beautifulsoup4-4.5.3,但是IDLE还是出现error message后from bs4 import BeautifulSouppip3
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.`
Run Code Online (Sandbox Code Playgroud)
在我的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不断抛出错误信息
BeautifulSoup4 与 Python 3x 和 2x 兼容,但安装过程有点不同。以下是我为 Python 3x 安装它的方法。
访问http://www.crummy.com/software/BeautifulSoup/#Download或https://pypi.python.org/pypi/beautifulsoup4/4.3.2并下载 beautifulsoup4-4.3.2.tar.gz。
导航到您下载文件的文件夹。使用7zip解压beautifulsoup4-4.3.2.tar.gz文件。
双击 beautifulsoup4-4.3.2.tar.gz 文件夹深入查看 dist 文件夹,然后提取 beautifulsoup4-4.3.2.tar 文件。
双击 beautifulsoup4-4.3.2.tar 文件夹以深入查看另一个 beautifulsoup4-4.3.2 文件夹。在 beautifulsoup4-4.3.2 文件夹中,您将看到 setup.py 文件。
按住 Shift 键,同时右键单击文件夹内的任意位置,然后选择在此处打开命令窗口。
在命令提示符处键入:setup.py install 并按 Enter。
当安装停止运行时,通过导航到 C:\Python34\Lib\site-packages 目录来验证是否已安装该包。如果已安装,您将看到 bs4 目录。
通过转至开始 > 所有程序 > Python 3.4 > IDLE(Python 3.4 GUI 32 位)启动基本 IDE 来验证安装是否正常运行。
提示后输入:>>>from bs4 import BeautifulSoup
如果您没有收到错误,则说明正在运行。
| 归档时间: |
|
| 查看次数: |
13052 次 |
| 最近记录: |