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.

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

No luck. It was time.py earlier, I changed to something else but still same error.
Make sure there's no file in your current folder named datetime.py or datetime.pyc
You can check which datetime it is by print(datetime.__file__) after it's been imported.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.