3

I'm following this tutorial trying to implement argparse into a python script I'm writing.

When I run this snippet of code from the tutorial I receive the following error:

[05:51 PM] user Scripts> cat argparse.py
import argparse
parser = argparse.ArgumentParser()
parser.parse_args()



[05:51 PM] user Scripts> python3 argparse.py
Traceback (most recent call last):
  File "argparse.py", line 1, in <module>
    import argparse
  File "/home/brian/Documents/Scripts/argparse.py", line 2, in <module>
    parser = argparse.ArgumentParser()
AttributeError: 'module' object has no attribute 'ArgumentParser'

I'm running Python 3.3.2 and have installed argparse 1.2.1 using easy_install so I know it's on the system but I cannot determine what is causing the error.

Note: I've read this post and it is not related.

Community
  • 1
  • 1
ProfessionalAmateur
  • 4,447
  • 9
  • 46
  • 63
  • You don't need the easy_install version with 3.3.2 (or 2.7). It comes with those newer Pythons. – hpaulj Sep 16 '13 at 03:18
  • That is good to know. Im on a CentOS box so I had to do the `altinstall` in order not to break `yum`, the article I was following just had me do it. Thanks! – ProfessionalAmateur Sep 16 '13 at 04:50

1 Answers1

8

From the error message I am guessing your script is trying to import not from argparse package but from local /home/brian/Documents/Scripts/argparse.py module. Rename your file and try again.

zero323
  • 322,348
  • 103
  • 959
  • 935