I have some Python 2.7 code written that uses the argparse module. Now I need to run it on a Python 2.6 machine and it won't work since argparse was added in 2.7.
Is there anyway I can get argparse in 2.6? I would like to avoid rewriting the code, since I will be transferring this kind of code between the machines often. Upgrading python is not an option.
I should have clarified that the ideal solution would be something that does not require module installation.
在Centos,Scientific或Redhat上,您可以通过运行以下命令来解决此问题:for
yum install python-argparse
您可以通过pip或easy_install安装它: https : //pypi.python.org/pypi/argparse
您还可以获取argparse.py
文件(例如来自https://pypi.python.org/pypi/argparse )并将其放在与主python文件相同的文件夹中。
如果您使用的是类似Debian的系统,您可以简单地写一下:
apt-get install python-argparse
When I had this need I just installed argparse using pip: pip install argparse
. This worked fine for the python-2.6.6-66.el6_8.x86_64
that was installed on my vanilla CentOS 6.8 system. I later found out that this did not work on other systems running python-2.6.6-52.el6.x86_64
. As a result I ended up copying argparse related files from one system to the other.
ie all files and directories beginning with argparse in /usr/lib/python2.6/site-packages
Only after doing all this did I discover that I could have simply installed the python argparse rpm python-argparse
that comes with both distributions.
ie yum install python-argparse
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.