Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python pip argparse upgrade

Tags:

python

pip

I have been attempting to upgrade argparse on Ubuntu 16.04 to the latest version, but pip keeps saying that it is part of the standard library.

How can this package be upgraded?

$ sudo pip install argparse --upgrade
Collecting argparse
  Using cached argparse-1.4.0-py2.py3-none-any.whl
Installing collected packages: argparse
  Found existing installation: argparse 1.2.1
    Not uninstalling argparse at /usr/lib/python2.7, as it is in the standard library.
Successfully installed argparse-1.2.1

Thanks.

like image 275
dfernan Avatar asked Feb 07 '23 22:02

dfernan


1 Answers

Argparse is maintained as a separate package here: https://pypi.python.org/pypi/argparse Which is where pip is going to collect it.

But

As of Python >= 2.7 and >= 3.2, the argparse module is maintained within the Python standard library. For users who still need to support Python < 2.7 or < 3.2, it is also provided as a separate package....

So, you are getting the error because it is part of the standard library, but also available to install via pip if you are using a version of Python for which it isn't.

If you really need to install 1.4.0 try this: (worked for me on my Windows 2.7.11 install)

  • Download the gzip file, not the wheel, from the pypi downloads page
  • Uncompress the archive and open a terminal in the argparse-1.4.01 folder
  • Run python setup.py install (See the 'Install' section of first link)

And check you now have the correct version (hopefully):

>>> import argparse
>>> argparse.__version__
'1.4.0' 

Note:
This still leaves the original argparse.py (in ...Python27\Lib for me) intact, and places the 1.4.0 egg in site-packages, with an easy-install.pth file which I presume ensures that this version gets used in preference to the standard library one.

like image 193
SiHa Avatar answered Feb 21 '23 10:02

SiHa