Python ImportError for strptime in spyder for Windows 7

I canโ€™t understand for life what causes this very strange 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 have not finished debugging yet, so the exceptions have been raised and it hasnโ€™t finished normally yet), and then if I try to run it again, I get the following (only the end of the trace 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 lock is held by another thread.

I do not start multiple threads with Threading etc. The only way to get code to pass this point is to completely restart the computer. Restarting spyder will not work. The web search did not seem to give any directions or directions to others who had this.

Does anyone understand what is happening? Is this some kind of GIL problem? What is import blocking and why does it stop me from importing this method of the datetime module as soon as I already tried to run the code once?

+7
source share
1 answer

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

eg.

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

All Articles