我正在尝试在Python3.4中安装Beautiful Soup4。我从命令行安装了它(得到了无效语法错误,因为我没有转换它),运行2to3.py转换脚本到bs4,现在我得到一个新的无效语法错误。
>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
from bs4 import BeautifulSoup
File "C:\Python34\bs4\__init__.py", line 30, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "C:\Python34\bs4\builder\__init__.py", line 4, in <module>
from bs4.element import (
File "C:\Python34\bs4\element.py", line 1213
print 'Running CSS selector "%s"' % selector
^
SyntaxError: Missing parentheses in call to 'print'有什么想法吗?
发布于 2015-05-09 20:41:24
Python4 not需要手动转换才能在Python3上运行。您正在尝试运行仅与Python2兼容的代码;看起来您未能正确转换代码库。
从BeautifulSoup 4 homepage
Beautiful Soup4可以在Python2 (2.6+)和Python3上运行。
现在抛出异常的代码行应该是:
print('Running CSS selector "%s"' % selector)代码库确实使用Python2语法,但是setup.py安装程序会将其转换为兼容的Python3语法。确保使用pip安装项目
pip install beautifulsoup4或者使用与Python3.4捆绑的pip版本:
python3.4 -m pip install beautifulsoup4或者使用easy_install
easy_install beautifulsoup4如果您只下载了tarball,那么至少要运行
python3.4 setup.py install让安装程序为您正确转换代码库;转换后的代码将复制到您的Python安装程序中。您可以在运行该命令后丢弃下载的源目录,请参阅。
或者,运行:
python3.4 setup.py build并跨build/lib目录进行复制。同样,do 使用原始源目录,因为它保持不变。
https://stackoverflow.com/questions/30140034
复制相似问题