How can I get argparse in Python 2.6?

北战南征 提交于 2019-11-27 03:43:09

问题


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.


回答1:


You can install it via pip or easy_install: https://pypi.python.org/pypi/argparse




回答2:


On Centos, Scientific, or Redhat, you can fix this by running the command:for

yum install python-argparse



回答3:


you can also get the argparse.py file (e.g. from https://pypi.python.org/pypi/argparse) and put it in the same folder as your main python file.




回答4:


If you are on Debian-like systems, you may simply write this:

apt-get install python-argparse



回答5:


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.

i.e. 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.

i.e. yum install python-argparse



来源:https://stackoverflow.com/questions/15330175/how-can-i-get-argparse-in-python-2-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!