Reputation:
I keep getting this traceback. I've used BeautifulSoup before with Python3 so I'm kind of confused as to why I would get this error now...
'''Traceback (most recent call last):
File "spider.py", line 7, in
from bs4 import BeautifulSoup
File "/home/cambam/Desktop/Python/Coursera/P4E/CapStone/pagerank/bs4/init.py", line 54
'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
'''
Upvotes: 2
Views: 2143
Reputation: 20415
Obtaining python2 code in the first place sounds inconvenient. Better to grab the right version at the outset.
Delete the old Soup code you downloaded, and grab a fresh copy:
$ python3 -m pip install beautifulsoup4
If you look at which pip
or pip --version
you may notice that it corresponds to python2. Using the -m
module syntax above will ensure that you get a proper python3 version that installs libraries where python3 will look for them.
Upvotes: 2
Reputation:
OK I already figured out the answer.
First I ran 'sudo apt install 2to3' in the command line
Then 2to3 -w bs4
I ran the program again and now it works.
Upvotes: 0