This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: AttributeError: 'module' object has no attribute 'ArgumentParser'
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 2.7
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, David Friedman, bsduni, eric.araujo, ezio.melotti, r.david.murray
Priority: normal Keywords:

Created on 2014-03-03 09:05 by bsduni, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg212620 - (view) Author: bsduni (bsduni) Date: 2014-03-03 09:05

I have installed Python 2.7.6 fully (all the modules selected). I attempted run some Python codes that were developed by a past staff, and am stuck with an issue with argparse. 

For ease of explanation I am using the example given in this website at

When I create a simple program with codes below:

import argparse
parser = argparse.ArgumentParser()

and execute with $ python, the following is the error message I receive:
Traceback (most recent call last):
  File "", line 2, in <module>
    parser = argparse.ArgumentParser()
AttributeError: 'module' object has no attribute 'ArgumentParser'

I also tried to add argparse additionally using pip install and the problem remains the same.

Would be grateful if someone could help to overcome this AttributeError.
msg212622 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2014-03-03 09:25
I guess that there is argparse module in current directory, which overrides argparse module from standard library.
Use e.g. print(argparse) or print(argparse.__file__) to find it.
A correct location would be something like /usr/lib64/python2.7/argparse.pyc.
msg212686 - (view) Author: bsduni (bsduni) Date: 2014-03-03 23:03
Unfortunately it is not that case, ie, no argparse in my current working directory /home/bsduni/pytests/ (on a FreeBSD 9.2 system).

The following are the locations I can find argparse in my system:






The the files in /usr/local/lib/python2.7/site-packages/ are from the 'pip install' which I tried when argparse didnot work after the installation of Python in full (ie, with argparse files in /usr/local/lib/python2.7/)
msg212688 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-03-03 23:20
Please show the output from

msg218162 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2014-05-09 12:51
Closing for lack of feedback.
Feel free to re-open if/when more info are available.
msg373913 - (view) Author: David Friedman (David Friedman) Date: 2020-07-18 19:22
I know this is 6 years too late, but I had this problem a few minutes ago on Python2.7.  Googling didn't find me anything relevant except this bug entry.  However, I found the cause myself: I had a test file named (and an argparse.pyc) in the current directory (i.e. $PYTHONPATH) which was overriding the one in the main python library path. Once I renamed my and argparse.pyc to something else, python found the real argparse and that message (the same one you saw) disappeared.
Date User Action Args
2022-04-11 14:57:59adminsetgithub: 65039
2020-07-18 19:22:58David Friedmansetnosy: + David Friedman
messages: + msg373913
2014-05-09 12:51:21ezio.melottisetstatus: pending -> closed
nosy: + ezio.melotti
messages: + msg218162

2014-04-16 18:20:19r.david.murraysetstatus: open -> pending
resolution: works for me
stage: resolved
2014-03-07 21:47:06eric.araujosetnosy: + eric.araujo
2014-03-03 23:20:09r.david.murraysetnosy: + r.david.murray
messages: + msg212688
2014-03-03 23:03:53bsdunisetmessages: + msg212686
2014-03-03 09:25:44Arfreversetnosy: + Arfrever
messages: + msg212622
2014-03-03 09:05:48bsdunicreate