2013-01-19 23 views
11

なぜこれが起こっていますか?ImportError:名前のログをインポートできません

python --version= 2.7.1

import urllib 

def main(): 
    urllib.urlretrieve('http://media2.apnonline.com.au/img/media/images/2011/02/28/apple-logo_fct825x508x16_t460.jpg', 'image.jpg') 

if __name__ == '__main__': 
    main() 

トレース:

Traceback (most recent call last): 
    File "robot.py", line 7, in <module> 
    main() 
    File "robot.py", line 4, in main 
    urllib.urlretrieve('http://media2.apnonline.com.au/img/media/images/2011/02/28/apple-logo_fct825x508x16_t460.jpg', 'image.jpg') 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 91, in urlretrieve 
    return _urlopener.retrieve(url, filename, reporthook, data) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 237, in retrieve 
    fp = self.open(url, data) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 205, in open 
    return getattr(self, name)(url) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 289, in open_http 
    import httplib 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 79, in <module> 
    import mimetools 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module> 
    import tempfile 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 34, in <module> 
    from random import Random as _Random 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 45, in <module> 
    from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil 
ImportError: cannot import name log 
+1

興味深い。私は実際に別のライブラリで同じ問題に遭遇しました。私のために – eandersson

+0

;その走っている罰金。 – namit

+0

私は:)確かに私は行う –

答えて

24

それはあなたが実行しているプログラムと同じディレクトリにあるmath.pyという名前のファイルを持っていることは可能ですか?もしそうなら、pythonは数学モジュールの前にそれをインポートしようとします。

ソリューション:ただ、何か他のものに名前を変更します。

ヒント:今後、モジュールの名前を矛盾しないようにしてください。

関連する問題