问题:如何更新Python包?

我正在运行Ubuntu 9:10,并安装了一个名为M2Crypto的软件包(版本为0.19.1)。我需要下载,构建和安装最新版本的M2Crypto软件包(0.20.2)。

0.19.1软件包的文件位于多个位置,包括(/ usr / share / pyshared和/usr/lib/pymodules.python2.6)。

在安装0.20.2之前,如何从系统中完全卸载版本0.19.1?

I’m running Ubuntu 9:10 and a package called M2Crypto is installed (version is 0.19.1). I need to download, build and install the latest version of the M2Crypto package (0.20.2).

The 0.19.1 package has files in a number of locations including (/usr/share/pyshared and /usr/lib/pymodules.python2.6).

How can I completely uninstall version 0.19.1 from my system before installing 0.20.2?


回答 0

您可能需要研究像pip这样的Python软件包管理器。如果您不想使用Python软件包管理器,则应该能够下载M2Crypto并通过旧安装进行构建/编译/安装。

You might want to look into a Python package manager like pip. If you don’t want to use a Python package manager, you should be able to download M2Crypto and build/compile/install over the old installation.


回答 1

我发现最好的方法是从终端运行此命令

sudo pip install [package_name] --upgrade

sudo 会要求输入您的root密码以确认操作。


注意:某些用户可能安装了pip3。在这种情况下,请使用

sudo pip3 install [package_name] --upgrade

The best way I’ve found is to run this command from terminal

sudo pip install [package_name] --upgrade

sudo will ask to enter your root password to confirm the action.


Note: Some users may have pip3 installed instead. In that case, use

sudo pip3 install [package_name] --upgrade

回答 2

要自动升级所有过时的软件包(已使用pip安装),只需运行以下脚本,

pip install $(pip list --outdated | awk '{ print $1 }') --upgrade

在这里,pip list --outdated将列出所有过期的软件包,然后将其通过管道传输到awk,因此它将仅打印名称。然后,$(...)将其设为变量,然后自动完成所有操作。确保您具有权限。(sudo如果您感到困惑,请放在pip前面)我会写一个脚本,pip-upgrade 代码如下:

#!/bin/bash
sudo pip install $(pip list --outdated | awk '{ print $1 }') --upgrade

然后使用以下脚本行进行准备:

sudo chmod +x pip-upgrade
sudo cp pip-upgrade /usr/bin/

然后,只需按一下pip-upgrade,瞧!

To automatically upgrade all the outdated packages (that were installed using pip), just run the script bellow,

pip install $(pip list --outdated | awk '{ print $1 }') --upgrade

Here, pip list --outdated will list all the out dated packages and then we pipe it to awk, so it will print only the names. Then, the $(...) will make it a variable and then, everything is done auto matically. Make sure you have the permissions. (Just put sudo before pip if you’re confused) I would write a script named, pip-upgrade The code is bellow,

#!/bin/bash
sudo pip install $(pip list --outdated | awk '{ print $1 }') --upgrade

Then use the following lines of script to prepare it:

sudo chmod +x pip-upgrade
sudo cp pip-upgrade /usr/bin/

Then, just hit pip-upgrade and voila!


回答 3

  1. 通过Windows命令提示符,运行:pip list --outdated 您将获得过期软件包的列表。
  2. 运行:pip install [package] --upgrade 它将升级[package]并卸载以前的版本。

要更新点:

py -m pip install --upgrade pip

同样,这将卸载以前版本的pip,并将安装最新版本的pip。

  1. Via windows command prompt, run: pip list --outdated You will get the list of outdated packages.
  2. Run: pip install [package] --upgrade It will upgrade the [package] and uninstall the previous version.

To update pip:

py -m pip install --upgrade pip

Again, this will uninstall the previous version of pip and will install the latest version of pip.


回答 4

  • 方法1:手动手动升级

pip install package_name -U
  • 方法2:一次全部升级(如果某些程序包无法升级,则很有可能会回滚

pip install $(pip list --outdated --format=columns |tail -n +3|cut -d" " -f1) --upgrade
  • 方法3:使用循环一一升级

for i in  $(pip list --outdated --format=columns |tail -n +3|cut -d" " -f1); do pip install $i --upgrade; done
  • Method 1: Upgrade manually one by one

pip install package_name -U
  • Method 2: Upgrade all at once (high chance rollback if some package fail to upgrade

pip install $(pip list --outdated --format=columns |tail -n +3|cut -d" " -f1) --upgrade
  • Method 3: Upgrade one by one using loop

for i in  $(pip list --outdated --format=columns |tail -n +3|cut -d" " -f1); do pip install $i --upgrade; done

回答 5

我认为最好的单线是:

pip install --upgrade <package>==<version>

I think the best one-liner is:

pip install --upgrade <package>==<version>

回答 6

使用pipupgrade

$ pip install pipupgrade
$ pipupgrade --latest --interactive

pipupgrade可帮助您从requirements.txt文件升级系统,本地或软件包!它还有选择地升级不会破坏更改的软件包。与Python2.7 +,Python3.4 +和pip9 +,pip10 +,pip18 +兼容。

在此处输入图片说明

注意:我是该工具的作者。

Use pipupgrade!

$ pip install pipupgrade
$ pipupgrade --latest --interactive

pipupgrade helps you upgrade your system, local or packages from a requirements.txt file! It also selectively upgrades packages that don’t break change. Compatible with Python2.7+, Python3.4+ and pip9+, pip10+, pip18+.

enter image description here

NOTE: I’m the author of the tool.


回答 7

该软件包最初是如何安装的?如果是通过apt进行的话,您就可以apt-get remove python-m2crypto

如果您是通过easy_install安装的,我敢肯定,唯一的方法就是将文件丢弃在lib,shared等目录下。

我将来的推荐?使用pip之类的工具安装软件包。此外,您可以查找一个称为virtualenv的东西,以便您的软件包是基于每个环境存储的,而不是仅基于root存储的。

使用pip,非常简单:

pip install m2crypto

但是您也可以使用正确的地址从git,svn等仓库中安装。所有这些都在pip文档中进行了说明

How was the package originally installed? If it was via apt, you could just be able to do apt-get remove python-m2crypto

If you installed it via easy_install, I’m pretty sure the only way is to just trash the files under lib, shared, etc..

My recommendation in the future? Use something like pip to install your packages. Furthermore, you could look up into something called virtualenv so your packages are stored on a per-environment basis, rather than solely on root.

With pip, it’s pretty easy:

pip install m2crypto

But you can also install from git, svn, etc repos with the right address. This is all explained in the pip documentation


回答 8

pip install -U $(pip list --outdated | awk 'NR>2 {print $1}')
pip install -U $(pip list --outdated | awk 'NR>2 {print $1}')

回答 9

在Juptyer笔记本中,一种非常简单的方法是

!pip install <package_name> --upgrade

因此,您只需要替换为实际的软件包名称即可。

In Juptyer notebook, a very simple way is

!pip install <package_name> --upgrade

So, you just need to replace with the actual package name.


回答 10

获取所有过时的软件包,并使用以下命令为每个过时的软件包创建批处理文件pip install xxx –upgrade

Get all the outdated packages and create a batch file with the following commands pip install xxx –upgrade for each outdated packages


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。