开发者

BeautifulSoup error in Python's Mechanize

I installed BeautifulSoup on my Mac using easy_install with no errors, And I can run the test.py file perfectly with no errors also. But when I try to use BeautifulSoup in another file, I get the error:

Traceback (most recent call last):
  File "/Users/Conor/Desktop/test.py", line 54, in <module>
    from BeautifulSoup import BeautifulSoup
ImportError: No module named BeautifulSoup

All I have on line 54 is from BeautifulSoup import BeautifulSoup And it gives me an error

What is going on here? How can I fix this?

NOTE: test.py contains:

from BeautifulSoup import BeautifulSoup
a = "<a>foo" * 10000
soup = BeautifulSoup(a)
soup.findAll("a")
soup.findAll(开发者_运维知识库"a", recursive=False)
print soup

EDIT:

OK I have been working away at this. Turns out if I move my test.py file INTO the folder where BeautifulSoup is located (/Documents/mechanize-0.2.5/BeautifulSoup/) it runs perfectly. Outside this folder, none of the files work. What the ** is going one here?!?!? And how do I fix it?


Did you install using sudo? It's odd that any easy_install module would end up in /Documents. (And it's odd that you have a Documents directory below the /Users level.)

On OS X (10.7.1) and I installed and used BeautifulSoup with no errors.

$ sudo pip install BeautifulSoup
$ python
>>>import BeautifulSoup
>>>BeautifulSoup.__file__
'/Library/Python/2.7/site-packages/BeautifulSoup.pyc'


Sounds like python doesn't know about the beautiful soup module. You should be able to import BS from any python script regardless of its location.

Not sure if this would work but you could try manually installing BS by changing to the beautiful soup directory and

python BeautifulSoup-x.py install

Where x is the version you are using.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜