标签归档:packages

我可以强迫pip重新安装当前版本吗?

问题:我可以强迫pip重新安装当前版本吗?

我遇到过以下情况:当前版本的软件包似乎无法正常工作,需要重新安装。但是,pip install -U不要触摸已经是最新的软件包。我看到了如何通过先卸载(使用pip uninstall)然后安装来强制进行重新安装,但是有没有办法在一个步骤中简单地将“更新”强制为名义上的当前版本?

I’ve come across situations where a current version of a package seems not to be working and requires reinstallation. But pip install -U won’t touch a package that is already up-to-date. I see how to force a reinstallation by first uninstalling (with pip uninstall) and then installing, but is there a way to simply force an “update” to a nominally current version in a single step?


回答 0

pip install --upgrade --force-reinstall <package>

升级时,请重新安装所有软件包,即使它们已经是最新的。

pip install -I <package>
pip install --ignore-installed <package>

忽略已安装的软件包(改为重新安装)。

pip install --upgrade --force-reinstall <package>

When upgrading, reinstall all packages even if they are already up-to-date.

pip install -I <package>
pip install --ignore-installed <package>

Ignore the installed packages (reinstalling instead).


回答 1

您可能希望拥有所有三个选项:--upgrade--force-reinstall确保重新安装,同时--no-deps避免重新安装依赖项。

$ sudo pip install --upgrade --no-deps --force-reinstall <packagename>

否则,您可能会遇到pip开始重新编译Numpy或其他大型软件包的问题。

You might want to have all three options: --upgrade and --force-reinstall ensures reinstallation, while --no-deps avoids reinstalling dependencies.

$ sudo pip install --upgrade --no-deps --force-reinstall <packagename>

Otherwise you might run into the problem that pip starts to recompile Numpy or other large packages.


回答 2

如果要重新安装Requirements.txt文件中指定的软件包而不进行升级,那么只需重新安装Requirements.txt文件中指定的特定版本:

pip install -r requirements.txt --ignore-installed

If you want to reinstall packages specified in a requirements.txt file, without upgrading, so just reinstall the specific versions specified in the requirements.txt file:

pip install -r requirements.txt --ignore-installed

回答 3

--force-reinstall

似乎没有强制使用python2.7和pip-1.5重新安装

我不得不用

--no-deps --ignore-installed
--force-reinstall

doesn’t appear to force reinstall using python2.7 with pip-1.5

I’ve had to use

--no-deps --ignore-installed

回答 4

如果您的文本文件包含大量软件包,则需要添加-r标志

pip install --upgrade --no-deps --force-reinstall -r requirements.txt

If you have a text file with loads of packages you need to add the -r flag

pip install --upgrade --no-deps --force-reinstall -r requirements.txt

回答 5

如果您需要强制重新安装pip本身,则可以执行以下操作:

python -m pip install --upgrade --force-reinstall pip

In the case you need to force the reinstallation of pip itself you can do:

python -m pip install --upgrade --force-reinstall pip

回答 6

sudo pip3 install --upgrade --force-reinstall --no-deps --no-cache-dir <package-name>==<package-version>

一些相关的答案:

点安装选项“忽略安装”和“强制重新安装”之间的区别

sudo pip3 install --upgrade --force-reinstall --no-deps --no-cache-dir <package-name>==<package-version>

Some relevant answers:

Difference between pip install options “ignore-installed” and “force-reinstall”


如何删除使用Python的easy_install安装的软件包?

问题:如何删除使用Python的easy_install安装的软件包?

Python easy_install使安装新软件包非常方便。但是,据我所知,它没有实现依赖项管理器的其他常见功能-列出和删除已安装的软件包。

找出已安装的软件包的最佳方法是什么,以及删除已安装软件包的首选方法是什么?如果我手动(例如,通过rm /usr/local/lib/python2.6/dist-packages/my_installed_pkg.egg类似方式)删除软件包,是否需要更新任何文件?

Python’s easy_install makes installing new packages extremely convenient. However, as far as I can tell, it doesn’t implement the other common features of a dependency manager – listing and removing installed packages.

What is the best way of finding out what’s installed, and what is the preferred way of removing installed packages? Are there any files that need to be updated if I remove packages manually (e.g. by rm /usr/local/lib/python2.6/dist-packages/my_installed_pkg.egg or similar)?


回答 0

pip是setuptools / easy_install的替代产品,提供了“卸载”命令。

根据安装说明安装pip :

$ wget https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py

然后,您可以使用pip uninstall删除与easy_install

pip, an alternative to setuptools/easy_install, provides an “uninstall” command.

Install pip according to the installation instructions:

$ wget https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py

Then you can use pip uninstall to remove packages installed with easy_install


回答 1

要卸载,.egg您需要rm -rf鸡蛋(可能是目录)并从中删除匹配的行site-packages/easy-install.pth

To uninstall an .egg you need to rm -rf the egg (it might be a directory) and remove the matching line from site-packages/easy-install.pth


回答 2

首先,您必须运行以下命令:

$ easy_install -m [PACKAGE]

它删除了程序包的所有依赖项。

然后删除该包装的鸡蛋文件:

$ sudo rm -rf /usr/local/lib/python2.X/site-packages/[PACKAGE].egg

First you have to run this command:

$ easy_install -m [PACKAGE]

It removes all dependencies of the package.

Then remove egg file of that package:

$ sudo rm -rf /usr/local/lib/python2.X/site-packages/[PACKAGE].egg

回答 3

所有的信息在其他的答案,但没有总结两者的请求,或者似乎使事情不必要的复杂性:

  • 对于您的搬迁需求,请使用:

    pip uninstall <package>

    (使用安装easy_install pip

  • 对于“列出已安装的软件包”,需要使用以下任一方法:

    pip freeze

    要么:

    yolk -l

    可以输出更多包装详细信息。

    (通过easy_install yolk或安装pip install yolk

All the info is in the other answers, but none summarizes both your requests or seem to make things needlessly complex:

  • For your removal needs use:

    pip uninstall <package>
    

    (install using easy_install pip)

  • For your ‘list installed packages’ needs either use:

    pip freeze
    

    Or:

    yolk -l
    

    which can output more package details.

    (Install via easy_install yolk or pip install yolk)


回答 4

网上有多个消息源建议通过使用-m选项重新安装软件包,然后仅删除lib /中的.egg文件和bin /中的二进制文件来破解。另外,可以在python bug跟踪器上找到有关setuptools问题的讨论,名称为setuptools issue 21

编辑:将链接添加到python bugtracker。

There are several sources on the net suggesting a hack by reinstalling the package with the -m option and then just removing the .egg file in lib/ and the binaries in bin/. Also, discussion about this setuptools issue can be found on the python bug tracker as setuptools issue 21.

Edit: Added the link to the python bugtracker.


回答 5

如果问题严重困扰您,您可以考虑使用virtualenv。它允许您创建一个封装python库的环境。您在此处而不是在全局site-packages目录中安装软件包。您在该环境中运行的所有脚本都可以访问这些程序包(也可以选择全局程序包)。在评估不确定/是否需要全局安装的软件包时,我经常使用此工具。如果您决定不需要该软件包,那么将虚拟环境吹走就很容易了。它很容易使用。制作一个新的环境:

$>virtualenv /path/to/your/new/ENV

virtual_envt在新环境中为您安装setuptools,因此您可以执行以下操作:

$>ENV/bin/easy_install

您甚至可以创建自己的boostrap脚本来设置新环境。因此,使用一个命令,您可以创建一个新的虚拟环境,例如默认安装了python 2.6,psycopg2和django(如果需要,您可以安装特定于环境的python版本)。

If the problem is a serious-enough annoyance to you, you might consider virtualenv. It allows you to create an environment that encapsulates python libraries. You install packages there rather than in the global site-packages directory. Any scripts you run in that environment have access to those packages (and optionally, your global ones as well). I use this a lot when evaluating packages that I am not sure I want/need to install globally. If you decide you don’t need the package, it’s easy enough to just blow that virtual environment away. It’s pretty easy to use. Make a new env:

$>virtualenv /path/to/your/new/ENV

virtual_envt installs setuptools for you in the new environment, so you can do:

$>ENV/bin/easy_install

You can even create your own boostrap scripts that setup your new environment. So, with one command, you can create a new virtual env with, say, python 2.6, psycopg2 and django installed by default (you can can install an env-specific version of python if you want).


回答 6

官方说明?:http : //peak.telecommunity.com/DevCenter/EasyInstall#uninstalling-packages

如果您用其他版本替换了软件包,则可以通过删除PackageName-versioninfo.egg文件或目录(位于安装目录中)来删除不需要的软件包。

如果要删除软件包的当前安装版本(或软件包的所有版本),则应首先运行:

easy_install -mxN PackageName

这样可以确保Python不会继续搜索您打算删除的软件包。完成此操作后,您可以安全地删除.egg文件或目录以及要删除的所有脚本。

Official(?) instructions: http://peak.telecommunity.com/DevCenter/EasyInstall#uninstalling-packages

If you have replaced a package with another version, then you can just delete the package(s) you don’t need by deleting the PackageName-versioninfo.egg file or directory (found in the installation directory).

If you want to delete the currently installed version of a package (or all versions of a package), you should first run:

easy_install -mxN PackageName

This will ensure that Python doesn’t continue to search for a package you’re planning to remove. After you’ve done this, you can safely delete the .egg files or directories, along with any scripts you wish to remove.


回答 7

尝试

$ easy_install -m [PACKAGE]

然后

$ rm -rf .../python2.X/site-packages/[PACKAGE].egg

try

$ easy_install -m [PACKAGE]

then

$ rm -rf .../python2.X/site-packages/[PACKAGE].egg

回答 8

要列出已安装的Python软件包,可以使用yolk -l。不过,您需要先使用easy_install yolk

To list installed Python packages, you can use yolk -l. You’ll need to use easy_install yolk first though.


回答 9

在尝试卸载随时间推移而安装的许多随机Python软件包时遇到了这个问题。

使用此线程中的信息,这是我想到的:

cat package_list | xargs -n1 sudo pip uninstall -y

package_list从清理(AWK)pip freeze中的virtualenv。

要删除几乎所有的Python软件包:

yolk -l | cut -f 1 -d " " | grep -v "setuptools|pip|ETC.." | xargs -n1 pip uninstall -y

Came across this question, while trying to uninstall the many random Python packages installed over time.

Using information from this thread, this is what I came up with:

cat package_list | xargs -n1 sudo pip uninstall -y

The package_list is cleaned up (awk) from a pip freeze in a virtualenv.

To remove almost all Python packages:

yolk -l | cut -f 1 -d " " | grep -v "setuptools|pip|ETC.." | xargs -n1 pip uninstall -y

回答 10

我在MacOS X Leopard 10.6.blah上遇到了同样的问题。

解决方案是确保您正在调用MacPorts Python:

sudo port install python26
sudo port install python_select
sudo python_select python26
sudo port install py26-mysql

希望这可以帮助。

I ran into the same problem on my MacOS X Leopard 10.6.blah.

Solution is to make sure you’re calling the MacPorts Python:

sudo port install python26
sudo port install python_select
sudo python_select python26
sudo port install py26-mysql

Hope this helps.


回答 11

对我而言,仅删除此文件:easy-install.pth有效,其余pip install django == 1.3.7

For me only deleting this file : easy-install.pth worked, rest pip install django==1.3.7


回答 12

这对我有用。它与先前的答案相似,但打包的路径不同。

  1. 须藤easy_install -m
  2. 须藤rm -rf /Library/Python/2.7/site-packages/.egg

平台:MacOS High Sierra版本10.13.3

This worked for me. It’s similar to previous answers but the path to the packages is different.

  1. sudo easy_install -m
  2. sudo rm -rf /Library/Python/2.7/site-packages/.egg

Plaform: MacOS High Sierra version 10.13.3