Python 2.6 导入错误:没有名为 argparse 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21359400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python 2.6 ImportError: No module named argparse
提问by user3236698
I'm trying to run git-cola from Red Hat Enterprise Linux Server release 6.5 and receive:
我正在尝试从 Red Hat Enterprise Linux Server 6.5 版运行 git-cola 并收到:
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.
我在其他博客中读到 Python 2.6 可能存在问题,可能需要迁移到 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:
附加信息 - @iljau 注意到 argparse 是 32 位库,而 python 的其余部分是 64 位。我会期望:
easy_install argparse
would have sorted this out and installed the 64 bit version.
本来可以解决这个问题并安装 64 位版本。
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.
附加问题:有谁知道如何安装 64 位版本的 argparse。我在互联网上搜索并不明显。我会继续寻找。
I installed argparse by downloading the tar file and
我通过下载 tar 文件安装了 argparse
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.
但是,它仍然将它安装在 lib 而不是 lib64 路径中 - 它看起来像 64 位安装。因此,正确引用 argparse 一定是其他问题。我不太了解 Python 来调试它,但我怀疑 git-cola 需要为 Python 2.6 做一些工作。
回答by iljau
As a simple solution copy argparse.pyfrom https://code.google.com/p/argparse/source/browse/argparse.pyto your project folder.
作为argparse.py从https://code.google.com/p/argparse/source/browse/argparse.py复制到您的项目文件夹的简单解决方案。
And indeed, for Python 2.6 argparseneeds to be installed separately.
事实上,Python 2.6argparse需要单独安装。
From: https://pypi.python.org/pypi/argparse
来自: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.
对于Python> = 2.7的..的argparse模块Python标准库中维护。对于仍然需要支持 Python < 2.7 .. 的用户,它也作为单独的包提供,它..也支持旧的 Python 版本。
But even after you install argparse, it may refuse to work for some mysterious reasons.
但即使在您安装之后argparse,它也可能会因为一些神秘的原因而拒绝工作。
Additional debugging tips may be found in answers and comments to question "ImportError: No module named argparse".
可以在问题“ImportError: No module named argparse”的答案和评论中找到其他调试技巧。
回答by user3236698
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:
使用 sudo 安装它们会使新安装的目录和文件无法被所有人读取。一个递归的 chmod 来打开所有已安装的路径,因为所有人都可读,解决了这个问题:
chmod -R u+rwX,go+rX,go-w <new directories and files>
回答by Jasem Elayeb
I had the same problem on RHEL6 and the solution was installing the package python-argparse.noarch:
我在 RHEL6 上遇到了同样的问题,解决方案是安装软件包python-argparse.noarch:
yum install python-argparse.noarch
then everything was fine.
然后一切都很好。
回答by Sidharth
Looks like argparse is missing.
看起来缺少 argparse。
yum install python-argparse

