BeautifulSoup invalid syntax in Python 3.4 (after 2to3.py)

孤街醉人 提交于 2019-12-01 08:40:17

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.

From the BeautifulSoup 4 homepage:

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)

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

or using the pip version bundled with Python 3.4:

python3.4 -m pip install beautifulsoup4

or using easy_install:

easy_install beautifulsoup4

If you downloaded just the tarball, at the very least run

python3.4 setup.py install

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.

Alternatively, run:

python3.4 setup.py build

and copy across the build/lib directory. Again, do not use the original source directory as it is left untouched.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!