Python ImportError for strptime in spyder for windows 7
Asked Answered
S

1

7

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?

Seismoscope answered 30/4, 2013 at 21:57 Comment(2)
Does this help? It seems to be a known bug. Could a module you're using be using threading?Misconception
Interesting, that worked, thanks. Adding the Dummy call to datetime.datetime.strptime at the beginning solved the issue.Seismoscope
S
13

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')
Seismoscope answered 1/5, 2013 at 16:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.