简体   繁体   English

无法安装Beautifulsoup

[英]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: 我在安装BeautifulSoup4(在带Python 3.3的OSX 10.6上运行)时遇到了一些麻烦,但几个小时以来我一直试图解决它,但是它不起作用...那就是我的做法:

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. 尽管它已安装到python 2.7的库文件夹中。 Opening the IDLE of python I typed the following to see weather it is working or not 打开python的IDLE我输入了以下内容以查看其是否正常运行

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. 我已经在Google上搜索了很多,但是论坛中建议的每种解决方案都无效。 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. 我已经下载了python 3.4,因为它带有pip,但我没有在python 3.3上安装它,但是bs4却无法与python 3.4一起使用。 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. 我将安装在python 2.7文件夹中的beautifulsoup文件夹移到了python 3.3的sitepackage文件夹中-均无效。

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 后者给了我很多错误信息,在一些bs4代码中,它们全都是“无效语法” ...即

.
...
....
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. pip可能已与python2.7一起安装。 You should explicitly invoke the setup script with python3 — python3 get_pip.py 您应该使用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. 我的系统是Windows 8中,我已经安装了Python 2.7和Python 3.3。 When under Python 3.3, from bs4 import BeautifulSoup caused this: 当Python 3.3下, from bs4 import BeautifulSoup导致此:

...Python33\\lib\\site-packages\\bs4__init__.py, line 175, pos 29 ... Python33 \\ lib \\ site-packages \\ bs4__init __。py,第175行,位置29
except Exception, e: 除例外,e:
^ ^
SyntaxError: invalid syntax SyntaxError:语法无效

So I uninstalled bs4 in Python 2.7 and Python 3.3. 所以我在Python 2.7和Python 3.3中卸载了bs4。 Then in Git I did: 然后在Git中,我做了:

pip3 install BeautifulSoup4    

This succeeded and now everything is ok. 这成功了,现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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