48

I encountered a problem while installing pip install pytorch-nlp.
The error is as follows:

ERROR: Could not 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 running:

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'.

2
  • I had the same error, but also multiple problems when installing other libraries including an ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory where I had to enable Windows Long Path Support. After enabling the long path support, I removed every numpy file and directory inside the site-packages of the virtual environment and reinstalled numpy, which then worked. I'm not 100% sure the problems are related, but they might be. Maybe also numpy was installed for a previous python version which I didn't want to use for the virtual env. Commented Feb 20, 2024 at 19:07
  • I guess the question can be changed to how to resolve faulty numpy installations Commented Apr 16 at 18:24

6 Answers 6

92

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
    
  2. Check for extraneous numpy packages from your site-packages folder.

    ls $SITE_PACKAGES_FOLDER/numpy*
    
  3. Trash extraneous packages.

    pip install trash-cli
    trash-put $SITE_PACKAGES_FOLDER/numpy*
    
  4. Reinstall numpy.

    pip install --upgrade numpy
    
Sign up to request clarification or add additional context in comments.

Comments

25

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 works for both cases
    • global environment
    • local or project-related environment
  • Else you will have to delete that environment and create a new one

3 Comments

My answer is a bit manual but kinda similar to the top answer
Dunno if it's the "right" way but it worked for me! Just blow it up and try again :)
This answer is the only one that worked for me , for anyone that comes later and doens't know where the site packages folder is: the path is in the error. these types of errors are why I prefer working on ubuntu or mint
19

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.

4 Comments

What if anaconda isn't installed?
maybe pip install --upgrade --force-reinstall <package>
It didn't work. Gives the same error as the OP. Upon investigation, I found that there were two dist-info for numpy, one for each version in my site-packages. This happened after I had tried to upgrade numpy. Deleting the older dist-info fixed it for me.
conda install numpy --force-reinstall worked for me! \o/
8
pip install --force-reinstall --no-deps numpy==1.21.2 --ignore-installed

This should solve the problem.

Comments

0

Dealing with Ansible I had conflicting items of docker and docker-py. Only one should be present.

- name: Uninstall conflicting Docker Python modules
  pip:
    name:
      - docker
      - docker-py
    state: absent

- name: Install Docker Python module
  pip:
    name: docker
    state: present

Comments

-1

Try to run this command:

python.exe -m pip install --upgrade pip

It worked for me to fix:

Cannot uninstall numpy 1.21.2, RECORD file not found

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.