I am trying to run a Python program but get the error
ImportError: No module named argparse
I found the question “argparse Python modules in cli” here on StackOverflow and tried the first comment, i.e. running the command
python -c "import argparse; print argparse"
which resulted in
<module 'argparse' from '/usr/lib/python2.7/argparse.pyc'>
For me it seems like there is Python 2.7 installed on the machine (of which I am not administrator) and the argparse
module is present as well. So I wonder why the module is not found. On another machine the script runs as it should. In the post referred to above, there is the comment that maybe sys.path
is broken. I have no clue what that means, or how I can change its value. Any ideas?
sys.version
? – Triciatrick#!
at the start of it) that tells it to use a different Python executable than the default? – Paphian/usr/bin/env python -c "import argparse; print argparse"
. (Note the difference with the line you ran before). – Paphiandpkg -l | grep libpython
? Also, are you running the script via a IDEor via CLI? – Urselecho -e '#!/usr/bin/env python\nimport argparse; print argparse' > test.py; python test.py
. – Paphian