当前位置:  开发笔记 > 编程语言 > 正文

PyCharm无法导入BeautifulSoup

如何解决《PyCharm无法导入BeautifulSoup》经验,为你挑选了1个好方法。

我试图在Python上使用bs4制作一个蜘蛛,我已经使用pip和easy_install安装了bs4,但是一旦我使用PyCharm运行程序,就会出错:

Traceback (most recent call last):
  File "C:/PyCharm Project/bs4.py", line 3, in 
    from bs4 import BeautifulSoup
  File "C:\PyCharm Project\bs4.py", line 3, in 
    from bs4 import BeautifulSoup
ImportError: cannot import name 'BeautifulSoup'

Process finished with exit code 1

但是在cmd提示符中没有出现此错误:

C:\WINDOWS\system32>python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup
>>>
>>> html_doc = """
... The Dormouse's story
... 
... 

The Dormouse's story

... ...

Once upon a time there were three little sisters; and their names were ... Elsie, ... Lacie and ... Tillie; ... and they lived at the bottom of a well.

... ...

...

... """ >>> >>> # create a bs object using a HTML page ... soup = BeautifulSoup(html_doc, 'html.parser', from_encoding='utf-8') >>> soup.title The Dormouse's story >>> soup.title.string "The Dormouse's story" >>>

项目翻译:



1> Padraic Cunn..:

您调用了脚本C:/PyCharm Project/bs4.py",from bs4 import BeautifulSoup实际上是在尝试BeautifulSoup从您自己的脚本而不是bs4lib 导入,因此您需要重命名它并删除.pyc目录中的任何文件.

推荐阅读
手机用户2402851155
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有