Invalid BeautifulSoup syntax in Python 3.4 (after

I am trying to install Beautiful Soup 4 in Python 3.4. I installed it from the command line (got an invalid syntax error because I didn't convert it), did the conversion from the

script to bs4

, and now I am getting 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\", line 30, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "C:\Python34\bs4\builder\", line 4, in <module>
    from bs4.element import (
  File "C:\Python34\bs4\", line 1213
    print 'Running CSS selector "%s"' % selector
SyntaxError: Missing parentheses in call to 'print'


Any ideas?


source to share

1 answer

BeautifulSoup 4 makes it unnecessary to manually convert to run in Python 3. Instead, you're trying to run Python 2-only code; it seems that you failed to convert the codebase correctly.

From the BeautifulSoup 4 page :

Beautiful Soup 4 works in both Python 2 (2.6+) and Python 3.

The line that is now throwing the exception should read:

print('Running CSS selector "%s"' % selector)


The codebase uses Python 2 syntax, but the installer will

convert this to compatible Python 3 syntax for you. Remember to install the project with pip


pip install beautifulsoup4


or using the version pip

bundled with Python 3.4:

python3.4 -m pip install beautifulsoup4


or using easy_install


easy_install beautifulsoup4


If you only downloaded the tarball, at least run

python3.4 install


for the installer to convert the codebase correctly for you; the converted code is copied to your Python setup. You can discard the loaded source directory after running the command, see How the installation works .

Alternatively, run:

python3.4 build


and copy the directory build/lib

. Again, don't use the original source directory as it remains intact.



All Articles