如何更新 Python 包?

发布于 2024-10-19 21:34:57 字数 228 浏览 9 评论 0原文

我正在运行 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

路弥 2024-10-26 21:34:57

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

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
我要还你自由 2024-10-26 21:34:57

您可能想研究一下 Python 包管理器,例如 pip。如果您不想使用 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.

花期渐远 2024-10-26 21:34:57

要自动升级所有过时的软件包(使用 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!

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

更新 pip:

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:

pip install --upgrade pip

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

颜漓半夏 2024-10-26 21:34:57
  • 方法一:手动一一升级

pip install package_name -U
  • 方法二:一次性全部升级(如果某个包升级失败,很有可能回滚

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

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
木槿暧夏七纪年 2024-10-26 21:34:57

我认为最好的一句话是:

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

I think the best one-liner is:

pip install --upgrade <package>==<version>
ゞ记忆︶ㄣ 2024-10-26 21:34:57

打开命令提示符或终端并使用以下语法

pip install --upgrade [package]==[specific version or latest version]

例如

pip install --upgrade numpy==1.19.1

Open Command prompt or terminal and use below syntax

pip install --upgrade [package]==[specific version or latest version]

For Example

pip install --upgrade numpy==1.19.1
如梦亦如幻 2024-10-26 21:34:57

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

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

我以后的推荐?使用 pip 之类的东西来安装你的软件包。此外,您可以查找名为 virtualenv 的内容,以便您的包按环境存储,而不是仅在根上。

使用 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

恋你朝朝暮暮 2024-10-26 21:34:57
pip install -U $(pip list --outdated | awk 'NR>2 {print $1}')
pip install -U $(pip list --outdated | awk 'NR>2 {print $1}')
雄赳赳气昂昂 2024-10-26 21:34:57

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

只为一人 2024-10-26 21:34:57

如何才能从系统中完全卸载之前的0.19.1版本
安装0.20.2?

为了卸载 M2Crypto 使用

pip uninstall M2Crypto

我需要下载、构建并安装最新版本的
M2Crypto 包 (0.20.2)。

为了安装最新版本,可以使用 PyPi

pip install M2Crypto 

来安装版本 20.2(过时的版本),运行

pip install M2Crypto==0.20.2

假设只想升级

pip install M2Crypto --upgrade # Or pip install M2Crypto -U

注意:

  • 取决于 Python 版本(以下是如何升级查找版本)可以使用不同的 pip 命令。假设您正在使用 Python 3.7,则可能会使用 pip3.7,而不是仅使用 pip

  • 使用 sudo 被认为不安全< /a>.


  • 现在有更好的实践来管理开发系统,例如:虚拟环境或开发容器。开发容器允许将整个开发环境(无论是模块、VS Code 扩展、npm 库……)放入 Docker 容器中。当项目结束时,人们会关闭容器。没有必要无缘无故地将所有这些要求保留在计算机中。如果您想阅读更多相关内容:Visual Studio 文档Github

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

In order to uninstall M2Crypto use

pip uninstall M2Crypto

I need to download, build and install the latest version of the
M2Crypto package (0.20.2).

In order to install the latest version, one can use PyPi

pip install M2Crypto 

To install the version 20.2 (an outdated one), run

pip install M2Crypto==0.20.2

Assuming one just wants to upgrade

pip install M2Crypto --upgrade # Or pip install M2Crypto -U

Notes:

  • Depending on one's Python version (here's how to find the version) one may use a different pip command. Let's say one is working with Python 3.7, instead of just using pip, one might use pip3.7.

  • Using sudo is considered unsafe.

  • Nowadays there are better practices to manage the development system, such as: virtual environments or development containers. The development containers allow one to put the entire development environment (be it modules, VS Code extensions, npm libraries,...) inside a Docker container. When the project comes to an end, one closes the container. There's no need to keep all of those requirements around in the computer for no reason. If you feel like reading more about it: Visual Studio Docs, Github.

静谧 2024-10-26 21:34:57

获取所有过时的软件包并使用以下内容创建一个批处理文件
命令
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

沦落红尘 2024-10-26 21:34:57

即:

python -m pip install --proxy <proxyserver_name>:<port#> <pkg_name> 

记住在设置变量后导出变量,以使它们可供外壳会话使用。

Windows:

添加到环境变量:

set HTTP_PROXY=<proxyserver_name>:<port#>

您可能必须先安装完整的 python 包

I.e.:

python -m pip install --proxy <proxyserver_name>:<port#> <pkg_name> 

Remember to export the variables after setting them, to make them available to the outer shell session.

Windows:

Add to environment variables:

set HTTP_PROXY=<proxyserver_name>:<port#>

You might have to install the full python package first

仲春光 2024-10-26 21:34:57

这是用于一次更新所有过时的软件包的脚本。

import subprocess
import sys

def update_packages():
    outdated_packages = subprocess.run(
        [sys.executable, "-m", "pip", "list", "--outdated"],
        capture_output=True, text=True
    )
    packages = [line.split("==")[0] for line in outdated_packages.stdout.splitlines()]
    for pkg in packages[2:]:
        one_pkg = list()
        for pkg_info in pkg.split(" "):
            if pkg_info != "":
                one_pkg.append(pkg_info)
        subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", one_pkg[0]])
        print("Updating", one_pkg[0])

if __name__ == "__main__":
    update_packages()

Here's the script for updating all the outdated packages at once.

import subprocess
import sys

def update_packages():
    outdated_packages = subprocess.run(
        [sys.executable, "-m", "pip", "list", "--outdated"],
        capture_output=True, text=True
    )
    packages = [line.split("==")[0] for line in outdated_packages.stdout.splitlines()]
    for pkg in packages[2:]:
        one_pkg = list()
        for pkg_info in pkg.split(" "):
            if pkg_info != "":
                one_pkg.append(pkg_info)
        subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", one_pkg[0]])
        print("Updating", one_pkg[0])

if __name__ == "__main__":
    update_packages()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文