How can I get argparse in Python 2.6?

前端 未结 5 834
庸人自扰
庸人自扰 2020-12-10 10:29

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.

I

相关标签:
5条回答
  • 2020-12-10 10:36

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

    apt-get install python-argparse
    
    0 讨论(0)
  • 2020-12-10 10:40

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

    0 讨论(0)
  • 2020-12-10 10:46

    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

    0 讨论(0)
  • 2020-12-10 10:52

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

    yum install python-argparse
    
    0 讨论(0)
  • 2020-12-10 10:54

    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.

    0 讨论(0)
提交回复
热议问题