1

I am getting the error ImportError: cannot import name 'timedelta'.

from this line in my code:

from datetime import timedelta, datetime

I just installed pandas using pip install pandas and also conda install -f pandas

I dont get any error when I write import pandas. When I write which python I get /Users/zpu/miniconda3/bin/python When I want to debug the first line is

/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
Pegah
  • 672
  • 2
  • 13
  • 23
  • Who is importing `timedelta` where? Show a complete error with complete stacktrace please. – deceze Jul 07 '16 at 13:17
  • Timedelta does not come from datetime module? If you shown your code, we could know better. –  Jul 07 '16 at 13:21
  • 1
    Show the code and copy paste the traceback, better than images... –  Jul 07 '16 at 13:21
  • image and the code are added to the post.. Thanks. – Pegah Jul 07 '16 at 13:22
  • 7
    It looks like your script name is `datetime.py`. If so, choose another name that doesn't clash with the standard library. – DeepSpace Jul 07 '16 at 13:31
  • Images of text are generally not recommended on SO. Giant images of text are _really_ annoying... Please see [Discourage screenshots of code and/or errors](http://meta.stackoverflow.com/q/303812/4014959). Sure, your screenshots aren't of code, per se, but there's still no benefit of posting them as images rather than as searchable text & they waste disk space and bandwidth. And they're annoying for people browsing on mobile devices. Etc. – PM 2Ring Jul 07 '16 at 13:46
  • Thanks for getting rid of those screenshots! – PM 2Ring Jul 07 '16 at 13:51

1 Answers1

6

As DeepSpace said, you must not name your script "datetime.py", since in that case, from datetime import timedelta would try to import a function/class called "timedelta" from your script, not the standard library.

randomdude999
  • 701
  • 7
  • 20
  • Thanks. That was the problem. In your opinion, is my list of pythons in Preferences OK, or I should remove python2.6? – Pegah Jul 07 '16 at 13:40
  • 1
    You usually don't need python 2.6, since it is really old and I know no programs that work in python 2.6 but not 2.7. – randomdude999 Jul 07 '16 at 13:42