Can't import pprint

Thrynn picture Thrynn · Aug 4, 2015 · Viewed 13.2k times · Source

Programming newbie here. Whenever I attempt to 'import pprint' in the Python IDLE, I get the following error:

>>> import pprint
Traceback (most recent call last):
  File "<pyshell#21>", line 1, in <module>
    import pprint
  File "C:\Python34\pprint.py", line 10, in <module>
    pprint(count)
NameError: name 'pprint' is not defined

Thought I would try to 'pip install pprint' in command line but that didn't work either:

PS C:\Python34> pip install pprint
Collecting pprint
Could not find a version that satisfies the requirement pprint (from versions: )
No matching distribution found for pprint 

I thought Python 3.4.3 was supposed to come with pprint module. How do I get it to work? Can't seem to import pprint but all other modules are working fine. I need the pprint module to work for completion of some exercises from Automate The Boring Stuff with Python. Thanks for looking at my question.

Answer

Robᵩ picture Robᵩ · Aug 4, 2015

You've named a program pprint. Rename your program to something other than pprint.py and remove any pprint.pyc file that might be present.