'Pip cannot find metadata file - EnvironmentError

Whenever I run pip to install the Flask packages like virtualenv in Ubuntu 16.04, I get this error:

pip install virtualenv

Requirement already satisfied: virtualenv in ./.local/lib/python3.5/site-packages (16.1.0) No metadata found in ./.local/lib/python3.5/site-packages Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/usr/.local/lib/python3.5/site-packages/virtualenv-16.1.0.dist-info/METADATA'

Here are my pip and python versions:

pip --version pip 19.0.1 from /usr/.local/lib/python3.5/site-packages/pip (python 3.5)

python3 --version Python 3.6.8

I already tried almost all that I get from the internet to solve this issue like:

/usr/.local/bin/pip install virtualenv

But I still get the same error.

I also go into the dist folder to copy the metadata.json with METADATA, but there's no metadata.json file inside.

cd /usr/.local/lib/python3.5/site-packages/virtualenv-16.1.0.dist-info/ cp metadata.json METADATA

cp: cannot stat 'metadata.json': No such file or directory

Please help me, I'm stucked with this issue for days. Thanks!



Solution 1:[1]

I meet the same problem

ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/root/anaconda3/lib/python3.6/site-packages/tornado-6.0.4.dist-info/METADATA

then I cd /root/anaconda3/lib/python3.6/site-packages/tornado-6.0.4.dist-info/ && ls

DESCRIPTION.rst  LICENSE.txt  metadata.json

finally, I did cp metadata.json METADATA solved the problem. maybe this is helpful to you.

Solution 2:[2]

I encountered the same problem recently.

Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '~/.local/lib/python3.7/site-packages/pip-19.0.1.dist-info/METADATA'

In the folder

~/.local/lib/python3.7/site-packages/pip-19.0.1.dist-info/

I found another one named pip-19.0.1.dist-info, and the last one contained all the required files for the pip.

I just used

cd ~/.local/lib/python3.7/site-packages/pip-19.0.1.dist-info/
cp -r ./pip-19.0.1.dist-info/* ./
rm -r ./pip-19.0.1.dist-info

Obviously that you need to replace python version with your own and also check if files

entry_points.txt  INSTALLER  LICENSE.txt  METADATA  RECORD  top_level.txt  WHEEL

are in here.

Maybe it will help you, luck.

Solution 3:[3]

I just ran into this with a different package, using Python 3.6.5 and pip 19.2.3. I was hesitant to use the solutions here (and on similar SO questions) so I just tried the following and it cleared up the issue:

pip install --force-reinstall package_with_metadata_issue

Note that my case was complaining about the black package, which was a dependency of something else I was trying to install (with a simple pip install other_package). Black had already been installed and working on my system for a while, so it's unclear how it got into a bad state or what changed in pip such that it couldn't handle the package's state.

To be specific, the OP could try:

pip install --force-reinstall virtualenv

Though it seems like many other people here had an issue with pip itself, so that may just be kicking the can down the road until pip is in a good state.

Solution 4:[4]

I think the root of your error is that your pip is configured to work with Python3.5 (and looks in its specific Pythonpath for the metadata), while your Python version is 3.6.8

Virtual environments in Python 3 have been made simpler, in my opinion, with the usage of the built-in venv. Also, your Python and Flask versions should coincide, which is here, not the case.

I'd suggest you take the following steps

python3 -m venv /path/to/new/virtual/environment

  • Activate the virtual environment by
cd /path/to/new/virtual/environment
source env/bin/activate

You now have an isolated, clean-slate environment, where you only have a single version of Python.

  • Run pip install --upgrade pip to upgrade the virtual environment pip to the version that is compatible with your Python version.

  • Run pip install flask, and install your whole stack from scratch, so that the libraries and Python executable versions are aligned.

Solution 5:[5]

I got same error

Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/home/vagrant/.local/lib/python3.7/site-packages/pip-18.1.dist-info/RECORD'

It seems that there is a conflict between /usr/bin/pip and /home/vagrant/.local/lib/python3.7/.

My solution is avoiding the error.

  • pip freeze > requirements.txt
  • I deleted the /home/user/.local/lib/python3.7 dir
  • sudo pip install --upgrade pip
  • pip install -r requirements.txt --user
  • fixed it

Solution 6:[6]

conda install -c conda-forge requests solved my problem. Of course, you need to reinstall the package that is problematic for you. Using pip to reinstall it did not work for me.

Solution 7:[7]

do "pip install cython" if you use python or do "pip3 install cython" if you use python3. I try so many different way and this finally works for me.

Check your actual error message, my error message was " note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure

× Encountered error while trying to install package. ??> cytoolz"

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 Stephen
Solution 2 Alexandr Vasilyev
Solution 3 totalhack
Solution 4
Solution 5
Solution 6 HappyFace
Solution 7