【发布时间】:2014-11-17 05:59:55
【问题描述】:
环境 Python版本:3.4.2 操作系统版本:OS X Mavericks
嗨,
我想用 python 做一些网页抓取示例。
所以,我创建了脚本文件并将其命名为“html.py”。 (在我的项目目录中)
但是,当我用 python3 执行它时,它会产生这样的错误。
------------------------------------------- 错误信息 -- ---------------------------------------------
Traceback (most recent call last):
File "html.py", line 1, in <module>
from bs4 import BeautifulSoup
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/__init__.py", line 30, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/builder/__init__.py", line 4, in <module>
from bs4.element import (
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/element.py", line 5, in <module>
from bs4.dammit import EntitySubstitution
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/dammit.py", line 11, in <module>
from html.entities import codepoint2name
File "/Users/tester/Project/Python/html.py", line 1, in <module>
from bs4 import BeautifulSoup
ImportError: cannot import name 'BeautifulSoup'
但是,我通过“sudo pip3 install BeautifulSoup4”安装了“BeautifulSoup4”。
而且,我检查了它是否安装在正确的路径中。
奇怪的是,我试图用 python3 shell 模式在不同的目录中导入“BeautifulSoup4”(例如,不在我的项目目录中),
它不会出错。
仅当我在该目录中执行脚本文件时才会出现错误。 (存在'html.py')
那么,为什么会这样呢?
而且,当我更改脚本文件名时,错误也会消失。 (html.py -> test_html.py)
文件名有什么问题?
我不允许使用模块名称作为我的脚本文件吗?
【问题讨论】:
标签: python python-3.x python-module