[英]Are there file naming rules for python?
環境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)
文件名怎么了?
我是否不能將模塊名稱用作腳本文件?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.