简体   繁体   中英

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. I am using a 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. 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

b. If not, how can one view the exact location (on the local device) of a package imported in a 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. 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. Options for handling this are provided in this answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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