简体   繁体   English

pip 卸载特定版本的包

[英]Pip uninstall specific version of a package

My objective is to uninstall a specific version of the numpy package using pip, conda, or any other method.我的目标是使用 pip、conda 或任何其他方法卸载特定版本的numpy包。 I am using a MacOS 12.0我正在使用 MacOS 12.0

I am encountering a problem in which pip list and conda list both show numpy==1.22.4 in the exact same environment, yet for some reason every time I start a python shell with this environment, an older version of numpy is imported.我遇到了一个问题,其中pip list和 conda conda list在完全相同的环境中都显示 numpy==1.22.4 ,但是由于某种原因,每次我在这个环境中启动 python shell 时,都会导入旧版本的 numpy 。 There are no extraneous files, modules, or env variables that could cause this behavior.没有可能导致此行为的无关文件、模块或环境变量。 There are few posts about un installing specific package versions - so my question is two-fold:关于取消安装特定软件包版本的帖子很少 - 所以我的问题有两个:

a.一个。 Is uninstalling a specific package version possible using pip/conda and是否可以使用 pip/conda 卸载特定的软件包版本和

b.湾。 If not, how can one view the exact location (on the local device) of a package imported in a python shell?如果不是,如何查看在 python shell 中导入的包的确切位置(在本地设备上)?

Any advice would be appreciated!任何意见,将不胜感激!

(tensorflow) demo % pip show numpy
Name: numpy
Version: 1.22.4

(tensorflow) demo % conda list | grep numpy
numpy                     1.22.4                   pypi_0    pypi

(tensorflow) demo % python
Python 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:24:38) 
[Clang 12.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'1.19.5'

One can identify whence a module loads by examining the __spec__ attribute.可以通过检查__spec__属性来识别模块从何处加载。 In this case, you can use在这种情况下,您可以使用

import numpy as np
print(np.__spec__.origin)

to identify where the location of the loaded module.识别加载模块的位置。

In this case, I strongly suspect this will show it is located in the user site , ie,在这种情况下,我强烈怀疑这将表明它位于用户站点中,即

~/.local/lib/python3.9/site-packages/numpy/__init__.py

The default for the Python site module is to prioritize user site, and Conda does nothing to block this. Python site模块的默认设置是优先考虑用户站点,而 Conda 没有阻止这一点。 Options for handling this are provided in this answer .此答案中提供了处理此问题的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM