如何更新 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
我发现的最好方法是从终端运行此命令
sudo
将要求输入您的 root 密码以确认操作。注意:某些用户可能安装了 pip3。在这种情况下,使用
The best way I've found is to run this command from terminal
sudo
will ask to enter your root password to confirm the action.Note: Some users may have pip3 installed instead. In that case, use
您可能想研究一下 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.
要自动升级所有过时的软件包(使用 pip 安装的),只需运行下面的脚本,
这里,
pip list --outdated
将列出所有过时的软件包,然后我们将其通过管道传递给 awk,所以它只会打印名字。然后,
$(...)
会将其设为变量,然后一切都会自动完成。确保您拥有权限。 (如果你感到困惑,只需将 sudo 放在 pip 之前)我会编写一个名为
pip-upgrade
的脚本代码如下,
然后使用以下几行脚本来准备它:
然后,只需点击
pip-upgrade
即可!To automatically upgrade all the outdated packages (that were installed using pip), just run the script bellow,
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 putsudo
before pip if you're confused)I would write a script named,
pip-upgrade
The code is bellow,
Then use the following lines of script to prepare it:
Then, just hit
pip-upgrade
and voila!pip list --outdated
您将获得过时软件包的列表。
pip install [package] --upgrade
它将升级
[package]
并卸载以前的版本。更新 pip:
同样,这将卸载以前版本的 pip 并安装最新版本的 pip。
pip list --outdated
You will get the list of outdated packages.
pip install [package] --upgrade
It will upgrade the
[package]
and uninstall the previous version.To update pip:
Again, this will uninstall the previous version of pip and will install the latest version of pip.
我认为最好的一句话是:
I think the best one-liner is:
打开命令提示符或终端并使用以下语法
例如
Open Command prompt or terminal and use below syntax
For Example
该软件包最初是如何安装的?如果是通过 apt 进行的,您可以执行
apt-get remove python-m2crypto
如果您是通过 easy_install 安装的,我很确定唯一的方法就是删除 lib 下的文件、分享等等。
我以后的推荐?使用 pip 之类的东西来安装你的软件包。此外,您可以查找名为 virtualenv 的内容,以便您的包按环境存储,而不是仅在根上。
使用 pip,这非常简单:
但您也可以使用正确的地址从 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:
But you can also install from git, svn, etc repos with the right address. This is all explained in the pip documentation
在Juptyer笔记本中,一个非常简单的方法是
,您只需替换为实际的包名称即可。
In Juptyer notebook, a very simple way is
So, you just need to replace with the actual package name.
为了卸载 M2Crypto 使用
为了安装最新版本,可以使用 PyPi
来安装版本 20.2(过时的版本),运行
假设只想升级
注意:
取决于 Python 版本(以下是如何升级查找版本)可以使用不同的 pip 命令。假设您正在使用 Python 3.7,则可能会使用
pip3.7
,而不是仅使用pip
。使用
sudo
被认为不安全< /a>.现在有更好的实践来管理开发系统,例如:虚拟环境或开发容器。开发容器允许将整个开发环境(无论是模块、VS Code 扩展、npm 库……)放入 Docker 容器中。当项目结束时,人们会关闭容器。没有必要无缘无故地将所有这些要求保留在计算机中。如果您想阅读更多相关内容:Visual Studio 文档、Github。
In order to uninstall M2Crypto use
In order to install the latest version, one can use PyPi
To install the version 20.2 (an outdated one), run
Assuming one just wants to upgrade
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 usepip3.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.
获取所有过时的软件包并使用以下内容创建一个批处理文件
命令
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
即:
记住在设置变量后导出变量,以使它们可供外壳会话使用。
Windows:
添加到环境变量:
您可能必须先安装完整的 python 包
I.e.:
Remember to export the variables after setting them, to make them available to the outer shell session.
Windows:
Add to environment variables:
You might have to install the full python package first
这是用于一次更新所有过时的软件包的脚本。
Here's the script for updating all the outdated packages at once.