问题
I'm trying to run git-cola from Red Hat Enterprise Linux Server release 6.5 and receive:
Traceback (most recent call last):
File "....../bin/git-cola", line 24, in <module>
from argparse import ArgumentParser
ImportError: No module named argparse
I think I have all of the required packages installed:
* git-1.7.1-3.el6_4.1.x86_64
* python-2.6.6-51.el6.x86_64
* PyQt4.x86_64 0:4.6.2-9.el6
* /usr/lib/python2.6/site-packages/argparse-1.2.1-py2.6.egg
I read in other blogs that there may be a problem with Python 2.6 and may need to move to 2.7.
Additional information - @iljau noticed that argparse is in a 32 bit lib, while the rest of python is in 64 bits. I would have expected that:
easy_install argparse
would have sorted this out and installed the 64 bit version.
Additional question: Does anyone know how to install the 64 bit version of argparse. It is not apparent to me from searching the internet. I will continue looking.
I installed argparse by downloading the tar file and
python setup.py install
However, it still installed it in the lib rather than lib64 path - and it looks like a 64 bit install. So something else must be the problem in referencing argparse properly. I don't know Python enough to debug it, but I suspect that git-cola needs some work for Python 2.6.
回答1:
As a simple solution copy argparse.py
from https://code.google.com/p/argparse/source/browse/argparse.py to your project folder.
And indeed, for Python 2.6 argparse
needs to be installed separately.
From: https://pypi.python.org/pypi/argparse
As of Python >= 2.7 .. the argparse module is maintained within the Python standard library. For users who still need to support Python < 2.7 .. it is also provided as a separate package, which .. also supports older Python versions.
But even after you install argparse
, it may refuse to work for some mysterious reasons.
Additional debugging tips may be found in answers and comments to question "ImportError: No module named argparse".
回答2:
I had the same problem on RHEL6 and the solution was installing the package python-argparse.noarch:
yum install python-argparse.noarch
then everything was fine.
回答3:
The new packages were installed in the path:
/usr/lib/python2.6/site-packages
Installing them with sudo left the newly installed directories and files unreadable by all. A recursive chmod to open all the installed paths as readable to all solved the problem:
chmod -R u+rwX,go+rX,go-w <new directories and files>
回答4:
Looks like argparse is missing.
yum install python-argparse
来源:https://stackoverflow.com/questions/21359400/python-2-6-importerror-no-module-named-argparse