用于Windows 7的spyder中的strptime的Python ImportError

Thu*_*ing 7 python datetime strptime importerror spyder

我不能为我的生活弄清楚是什么导致了这个非常奇怪的错误.

我在spyder IDE中为Windows 7运行python 2.7中的脚本.它在一个点上使用datetime.datetime.strptime.我可以运行一次代码并且看起来很好(虽然我还没有完成调试,所以异常已经引发并且还没有正常完成),然后如果我再次尝试运行它,我得到以下内容(仅回溯结束)显示):

文件"C:\ path\to\test.py",第220行,在std_imp
self.data [key] .append(dt.datetime.strptime(string_var,string_format_var))
ImportError:导入_strptime失败,因为导入lockis被保留通过另一个线程.

我没有使用Threading等运行多个线程.让代码超越这一点的唯一方法是完全重启计算机.重启spyder将无法正常工作.网络搜索似乎没有产生任何其他人的线索或迹象.

有谁知道发生了什么?这是某种GIL问题吗?什么是导入锁,为什么一旦我尝试运行代码一次,它似乎阻止我导入datetime模块的这个方法?

Thu*_*ing 12

正如mfitzp所指出的,解决方案是在脚本开头包含对datetime.datetime.strptime的虚拟调用.

例如

  # This is a throwaway variable to deal with a python bug
  throwaway = datetime.datetime.strptime('20110101','%Y%m%d')
Run Code Online (Sandbox Code Playgroud)