在Python 3.4 BeautifulSoup无效的语法(2to3.py后) [英] BeautifulSoup invalid syntax in Python 3.4 (after 2to3.py)
问题描述
我想在Python 3.4安装美味的汤4。我安装了它的命令行,(得到了无效的语法错误,因为我没有将它转换),跑了 2to3.py
转换脚本,以 BS4
,现在我得到一个新的无效语法错误。
I am trying to install Beautiful Soup 4 in Python 3.4. I installed it from the command line, (got the invalid syntax error because I had not converted it), ran the 2to3.py
conversion script to bs4
and now I get a new invalid syntax error.
>>> 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'
任何想法?
推荐答案
BeautifulSoup 4确实的不可以需要手工转换为Python的3运行您尝试运行code仅与Python兼容2代替;看来你没有正确地转换codeBase的。
BeautifulSoup 4 does not need manual converting to run on Python 3. You are trying to run code only compatible with Python 2 instead; it appears you failed to correctly convert the codebase.
美丽的汤4作品在两个Python 2中(2.6+)和Python 3。
Beautiful Soup 4 works on both Python 2 (2.6+) and Python 3.
该行现在抛出异常的应的阅读:
The line now throwing the exception should read:
print('Running CSS selector "%s"' % selector)
在codeBase的不使用Python语法2,但 setup.py
安装程序将它转换为你的Python兼容3语法。请确保安装项目PIP
:
The codebase does use Python 2 syntax, but the setup.py
installer converts this for you to compatible Python 3 syntax. Make sure to install the project with pip
:
pip install beautifulsoup4
或使用 PIP
版本与Python 3.4捆绑:
or using the pip
version bundled with Python 3.4:
python3.4 -m pip install beautifulsoup4
或使用的easy_install
:
easy_install beautifulsoup4
如果您刚刚下载的压缩包,的最起码的运行
If you downloaded just the tarball, at the very least run
python3.4 setup.py install
让安装程序正确地转换codeBase的你;转换后code是的复制到您的Python安装的。您可以在运行该命令后丢弃下载的源目录,请参见的安装工作原理的。
to have the installer correctly convert the codebase for you; the converted code is copied into your Python setup. You can discard the downloaded source directory after running the command, see How installation works.
另外,运行:
python3.4 setup.py build
和跨建立/ lib目录
目录复制。同样,做的不可以使用原来的源目录,因为它是保持不变。
and copy across the build/lib
directory. Again, do not use the original source directory as it is left untouched.
这篇关于在Python 3.4 BeautifulSoup无效的语法(2to3.py后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!