Python ImportError for strptime in spyder for windows 7

为君一笑 提交于 2019-12-22 04:42:31

问题


I can't for the life of me figure out what is causing this very odd error.

I am running a script in python 2.7 in the spyder IDE for windows 7. It uses datetime.datetime.strptime at one point. I can run the code once and it seems fine (although I haven't finished debugging, so exceptions have been raised and it hasn't completed normally yet), then if I try running it again I get the following (end of traceback only is shown):

File "C:\path\to\test.py", line 220, in std_imp
self.data[key].append(dt.datetime.strptime(string_var, string_format_var))
ImportError: Failed to import _strptime because the import lockis held by another thread.

I am not running multiple threads with Threading etc. The only way to get the code to make it past this point is to completely restart the computer. Restarting spyder won't work. Web searches haven't seemed to yield any clues or indications of others who have had this happen.

Does anyone understand what is going on? Is this some sort of GIL problem? What is the import lock, and why does it seem to be preventing me from importing this method of the datetime module once I have already tried running the code once?


回答1:


The solution, as noted by mfitzp, was to include a dummy call to datetime.datetime.strptime at the beginning of the script.

e.g.

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


来源:https://stackoverflow.com/questions/16309650/python-importerror-for-strptime-in-spyder-for-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!