Python wikiから最初の例を実行しようとしましたが、実行しようとすると:
$ python BaseHttpServer.py
エラーAttributeError: 'module' object has no attribute 'BaseHTTPRequestHandler' が表示されます。
Linux Mageia 2 64 ビットの Python 2.7.3 でテストしました。
Traceback (most recent call last):
File "BaseHTTPServer.py", line 9, in <module>
import BaseHTTPServer
File "/home/vanveber/BaseHttpServer/BaseHTTPServer.py", line 14, in <module>
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
AttributeError: 'module' object has no attribute 'BaseHTTPRequestHandler'
そして、Windows 7 64ビットのPython 2.7.3でそれ
Traceback (most recent call last):
File "BaseHTTPServer.py", line 11, in <module>
from BaseHTTPServer import BaseHTTPRequestHandler
File "C:\BaseHttpServer\BaseHTTPServer.py", line 11, in <module>
from BaseHTTPServer import BaseHTTPRequestHandler
ImportError: cannot import name BaseHTTPRequestHandler
しかし!
- BaseHttpServer は、標準 Python ライブラリのクラスです。
- Windows の Python GUIからこのコードを作成して実行すると、正しく動作します。
何が問題で、その理由は?!