0

Python installation seems to have gone wrong on my mac. I get the above error no matter what modules I try to use. For example simple code as below gives me the above error:

import datetime
print(datetime.MINYEAR)

The same thing works fine when I try from interactive shell.

What's going wrong?

I have installed python3.4. How can I check if my installation is correct?

I tried uninstalling (How to uninstall Python 2.7 on a Mac OS X 10.6.4?) and installing it again. But no luck.

Community
  • 1
  • 1
Aravind
  • 550
  • 7
  • 17

1 Answers1

1

Make your the file you're coding in isn't called datetime.py. Rename it to mydatetime.py and it should work.

If your file is called datetime.py, then

import datetime

attempts to import your own file as a module, and of course your file probably doesn't have MINYEAR as an attribute.

Edit: Make sure to also remove any files in your current working directory named datetime.py or datetime.pyc

As DSM pointed out, you can use print(datetime.__file__) to print where you are importing datetime module from. On my system, you can clearly see it's importing from a system library (.so file):

/usr/lib/python2.7/lib-dynload/datetime.x86_64-linux-gnu.so
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159