简体   繁体   English

Python pip argparse升级

[英]Python pip argparse upgrade

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. 我一直在尝试将Ubuntu 16.04上的argparse升级到最新版本,但是pip一直说它是标准库的一部分。

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. 谢谢。

Argparse is maintained as a separate package here: https://pypi.python.org/pypi/argparse Which is where pip is going to collect it. Argparse在这里作为一个单独的包维护: https ://pypi.python.org/pypi/argparse这是pip将收集它的地方。

But

As of Python >= 2.7 and >= 3.2, the argparse module is maintained within the Python standard library. 从Python> = 2.7和> = 3.2开始,argparse模块在Python标准库中维护。 For users who still need to support Python < 2.7 or < 3.2, it is also provided as a separate package.... 对于仍然需要支持Python <2.7或<3.2的用户,它也作为单独的包提供....

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 . 所以,你所得到的错误,因为它标准库的一部分,但也可以,如果你使用的是Python版本,这就是通过PIP安装。

If you really need to install 1.4.0 try this: (worked for me on my Windows 2.7.11 install) 如果你真的需要安装1.4.0试试这个:(在我的Windows 2.7.11安装上为我工作)

  • Download the gzip file, not the wheel, from the pypi downloads page 从pypi 下载页面下载gzip文件,而不是滚轮
  • Uncompress the archive and open a terminal in the argparse-1.4.01 folder 解压缩存档并在argparse-1.4.01文件夹中打开终端
  • Run python setup.py install (See the 'Install' section of first link) 运行python setup.py install (参见第一个链接的“Install”部分)

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. 这仍然保留原始的argparse.py (在...Python27\\Lib中),并将1.4.0 egg放在site-packages ,并带有一个easy-install.pth文件,我认为该文件确保使用此版本优先于标准库之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM