如何更新Python包?

时间:2022-09-20 10:28:29

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).

我正在运行Ubuntu 9:10,安装了一个名为M2Crypto的软件包(版本是0.19.1)。我需要下载、构建和安装最新版本的M2Crypto包(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).

这个0.19.1的包在很多位置都有文件,包括(/usr/共享/pyshared和/usr/lib/pymodules.python2.6)。

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

在安装0.20.2之前,我如何能在系统中彻底卸载0.19.1版本?

9 个解决方案

#1


30  

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.

您可能想要查看Python包管理器,如pip。如果您不想使用Python包管理器,您应该能够下载M2Crypto并在旧安装上构建/编译/安装。

#2


282  

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.

sudo将请求输入您的根密码以确认操作。

#3


28  

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

为了自动升级所有过时的包(使用pip安装),只需运行脚本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,

在这里,pip列表——过时的将列出所有过时的包,然后我们将它导入awk,所以它只打印名称。然后,$(…)将使它成为一个变量,然后,一切都自动完成。确保您有权限。(只要把sudo放在pip之前,如果你感到困惑)我会写一个脚本,pip-升级代码是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!

然后,就按下pip升级,瞧!

#4


16  

  1. Via windows command prompt, run: pip list --outdated You will get the list of outdated packages.
  2. 通过windows命令提示,运行:pip列表——过时的你会得到过时的软件包列表。
  3. Run: pip install [package] --upgrade It will upgrade the [package] and uninstall previous version.
  4. 运行:pip安装[包]——升级它将升级[包]和卸载之前的版本。

#5


5  

  • 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
  • 方法2:一次性升级(如果某些包无法升级,则可能会回滚。

pip install $(pip list --outdated --format=columns |tail -n +3|cut -d" " -f1) --upgrade
  • Method 3: Upgrade one by one using loop
  • 方法3:使用循环对一个进行升级。

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

#6


4  

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

包装最初是如何安装的?如果是通过apt,你就可以做apt-get删除pythonm2crypto。

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

如果您是通过easy_install安装的,我很确定唯一的方法就是在lib、shared等文件中删除文件。

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.

我对未来的建议?使用pip之类的东西来安装包。此外,您可以查找名为virtualenv的东西,以便您的包存储在每个环境的基础上,而不是单独存储在根上。

With pip, it's pretty easy:

用pip,很简单:

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

但是您也可以从git、svn、etc . repos安装正确的地址。这都是在pip文档中解释的。

#7


4  

I think the best one-liner is:

我认为最好的一句话是:

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

#8


2  

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

获取所有过时的包并创建一个批处理文件,并使用下面的命令pip安装xxx——升级每个过时的包。

#9


0  

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

#1


30  

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.

您可能想要查看Python包管理器,如pip。如果您不想使用Python包管理器,您应该能够下载M2Crypto并在旧安装上构建/编译/安装。

#2


282  

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.

sudo将请求输入您的根密码以确认操作。

#3


28  

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

为了自动升级所有过时的包(使用pip安装),只需运行脚本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,

在这里,pip列表——过时的将列出所有过时的包,然后我们将它导入awk,所以它只打印名称。然后,$(…)将使它成为一个变量,然后,一切都自动完成。确保您有权限。(只要把sudo放在pip之前,如果你感到困惑)我会写一个脚本,pip-升级代码是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!

然后,就按下pip升级,瞧!

#4


16  

  1. Via windows command prompt, run: pip list --outdated You will get the list of outdated packages.
  2. 通过windows命令提示,运行:pip列表——过时的你会得到过时的软件包列表。
  3. Run: pip install [package] --upgrade It will upgrade the [package] and uninstall previous version.
  4. 运行:pip安装[包]——升级它将升级[包]和卸载之前的版本。

#5


5  

  • 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
  • 方法2:一次性升级(如果某些包无法升级,则可能会回滚。

pip install $(pip list --outdated --format=columns |tail -n +3|cut -d" " -f1) --upgrade
  • Method 3: Upgrade one by one using loop
  • 方法3:使用循环对一个进行升级。

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

#6


4  

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

包装最初是如何安装的?如果是通过apt,你就可以做apt-get删除pythonm2crypto。

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

如果您是通过easy_install安装的,我很确定唯一的方法就是在lib、shared等文件中删除文件。

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.

我对未来的建议?使用pip之类的东西来安装包。此外,您可以查找名为virtualenv的东西,以便您的包存储在每个环境的基础上,而不是单独存储在根上。

With pip, it's pretty easy:

用pip,很简单:

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

但是您也可以从git、svn、etc . repos安装正确的地址。这都是在pip文档中解释的。

#7


4  

I think the best one-liner is:

我认为最好的一句话是:

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

#8


2  

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

获取所有过时的包并创建一个批处理文件,并使用下面的命令pip安装xxx——升级每个过时的包。

#9


0  

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