简体   繁体   中英

Trouble installing beautifulsoup

I have some trouble installing BeautifulSoup4 (working on OSX 10.6 with Python 3.3) I try to solve it since a couple of hours but it does not work... Thats how I did it:

I opened the terminal and typed

sudo easy_install pip

That worked fine without any errors.

Then I typed

pip install BeautifulSoup4

which worked as well. Although it got installed into the library-folder in python 2.7. Opening the IDLE of python I typed the following to see weather it is working or not

from bs4 import BeautifulSoup

It came back with the following message:

Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
from bs4 import BeautifulSoup
ImportError: No module named 'bs4'

I googled already a lot but every solution that is suggested in forums does not work. I downloaded already python 3.4, cause it comes with pip, I don't have it installed on python 3.3, but bs4 wont work with python 3.4 neither. I moved the beautifulsoup folder, which got installed in the python 2.7 folder, into the sitepackage folder of python 3.3 - did not work neither.

I tried to download the package from the website and installed it with this command

python setup.py install

as well as

python3 setup.py install

The latter gave me heaps of errormessages, all of them "Invalid Syntax" in some of the bs4 code... ie

.
...
....
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/__init__.py", line 175
except Exception, e:
                ^
SyntaxError: invalid syntax

byte-compiling /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/builder/__init__.py to __init__.cpython-34.pyc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/builder/_html5lib.py to _html5lib.cpython-34.pyc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/builder/_htmlparser.py to _htmlparser.cpython-34.pyc
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/builder/_htmlparser.py", line 76
except (ValueError, OverflowError), e:
                                  ^
SyntaxError: invalid syntax
....
..
.

I am out of ideas....

pip is probably being installed with python2.7. You should explicitly invoke the setup script with python3 — python3 get_pip.py

I also faced this problem today. My system is Windows 8, and I have installed Python 2.7 and Python 3.3. When under Python 3.3, from bs4 import BeautifulSoup caused this:

...Python33\\lib\\site-packages\\bs4__init__.py, line 175, pos 29
except Exception, e:
^
SyntaxError: invalid syntax

So I uninstalled bs4 in Python 2.7 and Python 3.3. Then in Git I did:

pip3 install BeautifulSoup4    

This succeeded and now everything is ok.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM