Python ImportError:无法导入名称日志
为什么会这样Python ImportError:无法导入名称日志,python,osx-lion,Python,Osx Lion,为什么会这样 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 re
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
回溯(最近一次呼叫最后一次):
文件“robot.py”,第7行,在
main()
文件“robot.py”,第4行,在main中
urllib.urlretrieve('http://media2.apnonline.com.au/img/media/images/2011/02/28/apple-logo_fct825x508x16_t460.jpg','image.jpg')
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py”,urlretrieve中的第91行
return _urlopener.retrieve(url、文件名、reporthook、数据)
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py”,检索中的第237行
fp=self.open(url、数据)
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py”,第205行,打开
返回getattr(self,name)(url)
open_http中的文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py”,第289行
导入httplib
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py”,第79行,在
进口美托尔
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py”,第6行,在
导入临时文件
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py”,第34行,在
从随机导入随机为_随机
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py”,第45行,在
从数学导入日志为_log,exp为_exp,pi为_pi,e为_e,ceil为_ceil
ImportError:无法导入名称日志
您是否可能在与正在运行的程序相同的目录中有一个名为math.py
的文件?如果是这样,python会尝试在数学模块之前导入它
解决方案:只需将其重命名为其他名称即可
提示:以后尝试以不冲突的方式命名模块。有趣。事实上,我在另一家图书馆遇到了同样的问题;“它运行良好。”富士——我想我们可能已经发现了问题。也许你也对它感兴趣。