Python: import 导入库文件错误

by Web全栈工程师 on 2012 年 11 月 15 日

运行python总是出现如下错误:

  File "/usr/local/lib/python2.7/urllib.py", line 30, in <module>
    from urlparse import urljoin as basejoin
  File "/usr/local/lib/python2.7/urlparse.py", line 110, in <module>
    from collections import namedtuple
  File "/usr/local/lib/python2.7/collections.py", line 10, in <module>
    from keyword import iskeyword as _iskeyword
  File "/usr/local/lib/python2.7/urllib2.py", line 94, in <module>
    import httplib
  File "/usr/local/lib/python2.7/httplib.py", line 72, in <module>
    from urlparse import urlsplit
ImportError: cannot import name urlsplit

上网查了资料才发现,是因为在运行python脚本的目录下,是不允许有.pyc文件,

把目录下的.pyc文件移除,即可解决

Comments on this entry are closed.

Previous post:

Next post: