问题:删除点子的缓存?
我需要专门安装psycopg2 v2.4.1。我不小心做了:
pip install psycopg2
代替:
pip install psycopg2==2.4.1
它将安装2.4.4,而不是早期版本。
现在,即使在我pip卸载psycopg2并尝试使用正确的版本重新安装后,pip似乎仍在重新使用它第一次下载的缓存。
如何强制pip清除其下载缓存并使用命令中包含的特定版本?
I need to install psycopg2 v2.4.1 specifically. I accidentally did:
pip install psycopg2
Instead of:
pip install psycopg2==2.4.1
That installs 2.4.4 instead of the earlier version.
Now even after I pip uninstall psycopg2 and attempt to reinstall with the correct version, it appears that pip is re-using the cache it downloaded the first time.
How can I force pip to clear out its download cache and use the specific version I’m including in the command?
回答 0
如果使用的是pip 6.0或更高版本,请尝试添加该--no-cache-dir
选项。
如果使用的是pip 6.0之前的版本,请使用进行升级pip install -U pip
。
If using pip 6.0 or newer, try adding the --no-cache-dir
option.
If using pip older than pip 6.0, upgrade it with pip install -U pip
.
回答 1
在适合您的系统的地方清除缓存目录
Linux和Unix
~/.cache/pip # and it respects the XDG_CACHE_HOME directory.
OS X
~/Library/Caches/pip
视窗
%LocalAppData%\pip\Cache
Clear the cache directory where appropriate for your system
Linux and Unix
~/.cache/pip # and it respects the XDG_CACHE_HOME directory.
OS X
~/Library/Caches/pip
Windows
%LocalAppData%\pip\Cache
回答 2
From documentation at https://pip.pypa.io/en/latest/reference/pip_install.html#caching:
Starting with v6.0, pip provides an on-by-default cache which
functions similarly to that of a web browser. While the cache is on by
default and is designed do the right thing by default you can disable
the cache and always access PyPI by utilizing the --no-cache-dir
option.
回答 3
pip可以安装一个忽略缓存的软件包,像这样
pip --no-cache-dir install scipy
pip can install a package ignoring the cache, like this
pip --no-cache-dir install scipy
回答 4
在Ubuntu上,我必须删除/tmp/pip-build-root
。
On Ubuntu, I had to delete /tmp/pip-build-root
.
回答 5
(这里是点子维护者!)
由于PIP 6.0(后在2014年!) pip install
,pip download
并且pip wheel
命令可以告诉避免使用与高速缓存--no-cache-dir
选项。(例如:pip install --no-cache-dir <package>
)
自pip 10.0(早在2018年!)以来,pip config
添加了一个命令,该命令可用于将pip配置为始终忽略缓存- pip config set global.cache-dir false
将pip配置为不“全局”使用缓存(即,在所有命令中)。
从pip 20.1开始,pip具有pip cache
管理pip缓存内容的命令。
pip cache purge
删除缓存中的所有wheel文件。
pip cache remove matplotlib
有选择地从缓存中删除与matplotlib相关的文件。
总而言之,pip提供了许多调整缓存使用方式的方法:
pip install --no-cache-dir <package>
:仅为此运行而无需使用缓存安装软件包。
pip config set global.cache-dir false
:将pip配置为不“全局”使用缓存(在所有命令中)
pip cache remove matplotlib
:从pip的缓存中删除所有与matplotlib相关的wheel文件。
pip cache purge
:清除pip缓存中的所有文件。
问题中提到的“由于缓存而安装了错误版本”的特定问题已在pip 1.4中修复(早在2013年!):
修复了许多与清理和不重用构建目录有关的问题。(#413,#709,#634,#602,#939,#865,#948)
(pip maintainer here!)
Since pip 6.0 (back in 2014!), pip install
, pip download
and pip wheel
commands can be told to avoid using the cache with the --no-cache-dir
option. (eg: pip install --no-cache-dir <package>
)
Since pip 10.0 (back in 2018!), a pip config
command was added, which can be used to configure pip to always ignore the cache — pip config set global.cache-dir false
configures pip to not use the cache “globally” (i.e. in all commands).
Since pip 20.1, pip has a pip cache
command to manage the contents of pip’s cache.
pip cache purge
removes all the wheel files in the cache.
pip cache remove matplotlib
selectively removes files related to a matplotlib from the cache.
In summary, pip provides a lot of ways to tweak how it uses the cache:
pip install --no-cache-dir <package>
: install a package without using the cache, for just this run.
pip config set global.cache-dir false
: configure pip to not use the cache “globally” (in all commands)
pip cache remove matplotlib
: removes all wheel files related to matplotlib from pip’s cache.
pip cache purge
: to clear all files from pip’s cache.
The specific issue of “installing the wrong version due to caching” issue mentioned in the question was fixed in pip 1.4 (back in 2013!):
Fix a number of issues related to cleaning up and not reusing build directories. (#413, #709, #634, #602, #939, #865, #948)
回答 6
如果您想--no-cache-dir
默认设置选项,可以将其放入pip.conf
:
[global]
no-cache-dir = false
的位置pip.conf
取决于您的操作系统。请参阅文档以获取更多信息。
If you like to set the --no-cache-dir
option by default, you can put this into pip.conf
:
[global]
no-cache-dir = false
The location of pip.conf
depends on your OS. See the documentation for more info.
回答 7
我只是遇到了类似的问题,发现获取pip升级软件包的唯一方法是删除以前未完成的安装或先前版本的pip可能遗留下的$PWD/build
(%CD%\build
在Windows上)目录(它现在删除了成功安装后生成目录)。
I just had a similar problem and found that the only way to get pip to upgrade the package was to delete the $PWD/build
(%CD%\build
on Windows) directory that might have been left over from a previously unfinished install or a previous version of pip (it now deletes the build directories after a successful install).
回答 8
在archlinux中,pip缓存位于〜/ .cache / pip上,我可以通过删除其中的http文件夹来解决问题。
On archlinux pip cache is located at ~/.cache/pip, I could solve my issue by removing the http folder inside it.
回答 9
在我的Mac上,我必须删除缓存目录 ~/Library/Caches/pip/
On my mac I had to remove the cache directory ~/Library/Caches/pip/
回答 10
回答 11
在Windows 7上,我必须删除%HOMEPATH%/pip
。
On Windows 7, I had to delete %HOMEPATH%/pip
.
回答 12
如果使用virtualenv,请build
在您的环境根目录下查找目录。
If using virtualenv, look for the build
directory under your environments root.
回答 13
我必须在Windows 7上删除%TEMP%\ pip-build
I had to delete %TEMP%\pip-build On Windows 7
回答 14
在Mac OS(小牛)上,我不得不删除 /tmp/pip-build/
On Mac OS (Mavericks), I had to delete /tmp/pip-build/
回答 15
更好的方法是删除缓存并重建它。这样,如果您再次为其他virtualenv安装它,它将使用缓存而不是每次安装时都进行构建。
例如,当您安装它时,它将说它使用了缓存的滚轮,
Processing <some_prefix>/Library/Caches/pip/wheels/d0/c4/e4/e49fd07bca8dda00dd6b4bbc606aa05a25aacb00d45747a47a/horovod-0.19.3-cp37-cp37m-macosx_10_9_x86_64.wh
只需删除该文件,然后重新开始安装即可。
A better way to do it is to delete the cache and rebuild it. In this way, if you install it again for other virtualenv, it will use the cache instead of building every time when you install it.
For example, when you install it, it will say it uses cached wheel,
Processing <some_prefix>/Library/Caches/pip/wheels/d0/c4/e4/e49fd07bca8dda00dd6b4bbc606aa05a25aacb00d45747a47a/horovod-0.19.3-cp37-cp37m-macosx_10_9_x86_64.wh
Just delete that one and restart your install.
回答 16
(…)似乎pip正在重新使用缓存(…)
我很确定这不是正在发生的事情。用来(错误地)重用构建目录而非缓存的Pip。此问题已在 2013年7月23日发布的pip版本1.4中修复。
(…) it appears that pip is re-using the cache (…)
I’m pretty sure that’s not what’s happening. Pip used to (wrongly) reuse build directory not cache. This was fixed in version 1.4 of pip which was released on 2013-07-23.