'Cannot uninstall numpy 1.21.2, RECORD file not found

I encountered a problem while installing pip install pytorch-nlp The erro is as follow:

ERROR: Could n`ot install packages due to an OSError: [Errno 2] No such file or directory: 'c:\\users\\pcpcpc\\anaconda3\\envs\\pytorch\\lib\\site-packages\\numpy-1.21`.2.dist-info\\METADATA'

SO I tried to reinstall numpy by

pip install --force-reinstall --no-deps numpy==1.21.2

But I get the error:

ERROR: Cannot uninstall numpy 1.21.2, RECORD file not found. You might be able to recover from this via: 'pip install --force-reinstall --no-deps numpy==1.21.2'.


Solution 1:[1]

As @Phoenix suggested, you might have an incomplete installation of numpy in your site-packages folder.

  1. Find your site-packages folder.
SITE_PACKAGES_FOLDER=$(python3 -c "import sysconfig; print(sysconfig.get_paths()['purelib'])")
echo $SITE_PACKAGES_FOLDER
  1. Check for extraneous numpy packages from your site-packages folder.
ls $SITE_PACKAGES_FOLDER/numpy*
  1. Trash extraneous packages.
pip install trash-cli
trash $SITE_PACKAGES_FOLDER/numpy*
  1. Reinstall numpy.
pip install --upgrade numpy

Solution 2:[2]

Try manually deleting the numpy files/directories and then do

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

One way to find the numpy files is to run

python -c "import numpy; print(numpy.__file__)"

For example, this prints out

/home/tink-user/workspace/.conda_envs/tink-payment-categorization/lib/python3.7/site-packages/numpy/__init__.py

for me. So you can go there:

cd /home/tink-user/workspace/.conda_envs/tink-payment-categorization/lib/python3.7/site-packages

then you can check with something like this to see which numpys are there:

ls numpy*
ls | grep numpy

Delete the numpy directories and try force reinstalling (pip install --upgrade --force-reinstall <package>).

Conda

This also happened to me in a conda environment after I ended up with multiple numpy installations and tried to manually delete them by removing the directories in site-packages. I had to force reinstall with conda (I think after manually deleting the directories for numpy): conda install numpy --force-reinstall.

Solution 3:[3]

  • None of the above solutions worked for me

What worked for me:

  • Delete that particular folder from the site-packages
    • Only delete the folder with the version number and not the folder that has python modules and files
    • Delete that folder with metadata files matching the numpy version in the warning and error message in the installation traceback
  • re-install the package
    • pip install numpy just as you would do
  • this work for both cases
    • global environment
    • local or project related environment
  • ** else you will have delete that environment and create a new one **

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 K_one28