90

I relatively new to coding so I am not (yet) running virtual environments. Rather, I am just downloading packages with pip straight to my pc to run python 3.7 in atom.

When I tried to use pip the other day to install the scrapy package like so -m pip install --user scrapy

I got this error: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'c:\\users\\adrian\\appdata\\roaming\\python\\python37\\site-packages\\pip-19.0.1.dist-info\\METADATA'

Most of the other answers I have seen on related errors had people use conda to install some type of fix I think? When I tried to use conda to execute one of the fixes I recieved a CondaHTTPError: SSLError(MaxRetryError('HTTPSConnectionPool(host=\'repo.anaconda.com\', port=443): Max retries exceeded with url: /pkgs/free/noarch/repodata.json.bz2 (Caused by SSLError("Can\'t connect to HTTPS URL because the SSL module is not available.

Any direction would be heartily appreciated :-)

Adrian Nesta
  • 1,001
  • 1
  • 6
  • 4
  • Possible duplicate of [Pip cannot find metadata file - EnvironmentError](https://stackoverflow.com/questions/54552367/pip-cannot-find-metadata-file-environmenterror) – phd Feb 20 '19 at 20:22
  • I added an alternative approach to the first duplicate listed here that may work for some folks: https://stackoverflow.com/a/58082184/10682164 – totalhack Sep 24 '19 at 14:26

21 Answers21

85

TL;DR:

Problem: Long install path

Solution 1: Install the desired python package (in my case tensorflow) in the folder which has a shorter path (for example C:/my_py_packages/some_package)

Solution 2: Set the registry value HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem@LongPathsEnabled to 1 as mentioned here.




Original answer: I got here by having this kind of error when I tried installing tensorflow library. My error was the following:

Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'c:\moj ifajlovi\faks\11master\1semestar\siap-sistemizaistrazivanjeianalizupodataka_(datamining)\projek at\rad\venvs\siap_venv\Lib\site-packages\tensorflow_estimator\python\estimator\canned\line ar_optimizer\python\utils\pycache\sharded_mutable_dense_hashtable.cpython-37.pyc'

So, there was no sharded_mutable_dense_hashtable.cpython-37.pyc file in the __pycache__ directory. But, sharded_mutable_dense_hashtable.cpython-37.pyc file was in the utils directory (which is the parent directory of __pycache__ directory).

That's why I tried manually copying the sharded_mutable_dense_hashtable.cpython-37.pyc file in the __pycache__ directory. When I tried that, I had a copy error which stated that the path was too long, so it couldn't put the file in the directory.

So, the solution:

Install the desired python package (in my case tensorflow) in the folder which has a shorter path (for example C:/my_py_packages/some_package) or set the registry value HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem@LongPathsEnabled to 1 as mentioned here.

Filip Savic
  • 2,737
  • 1
  • 29
  • 34
  • 14
    As another option you could enable support of long file names in Windows 10 by changing HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled registry value. – Dmitry Sobolev Jul 02 '19 at 05:05
  • 3
    The same error message can bite you when you pip install pytorch after getting python from Microsoft Store. +1 since your post got me onto the root cause "path too long", see https://www.reddit.com/r/pytorch/comments/c6cllq/issue_installing_pytorch/ – Jonas Heidelberg Aug 05 '19 at 22:05
  • @DmitrySobolev Thank you for the easy and useful option. I am using Windows 7 and I just checked and didn't find the LongPathsEnabled registry in FileSystem registry folder. – Filip Savic Aug 06 '19 at 23:11
  • 2
    I'd put the regedit solution as a tl;dr right at the start of the answer. I've almost skipped it here, and it's the right answer. – Elazar Nov 25 '19 at 08:27
  • 2
    @Elazar - I added a TL;DR. – Filip Savic Nov 26 '19 at 09:23
  • second solution worked for me. run the registry as administrator if needed – Valentin Mar 20 '21 at 12:00
  • 4
    in order to install the package in another loaction, you can use --target flag, e.g: pip3 install --upgrade --target="C:\Users\\" if you get an error: "ERROR: Can not combine '--user' and '--target'" you can add "--no-user" flag at the end – Amitay Drummer Jul 14 '21 at 12:23
  • This can be done by running `Set-ItemProperty -Path "HKLM:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1` – Jesper Hustad Oct 22 '21 at 11:58
63

This is what I did:

I could not install my python package due to this error ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'c:\\users\\banipreet\\anaconda3\\envs\\env-gpu\\lib\\site-packages\\requests-2.24.0.dist-info\\METADATA'

I simply removed this folder 'c:\\users\\banipreet\\anaconda3\\envs\\env-gpu\\lib\\site-packages\\requests-2.24.0.dist-info and retried pip install my-package, and it installed the package sucessfully.

24

Remove the 260 Character Path Limit by Editing the Registry, change LongPathsEnabled to 1, the regedit path in:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem

enter image description here

finally: restart your computer, or logout!

dayudodo
  • 463
  • 4
  • 7
14

First To Access The System Registry:

  1. Click Start, and then click Run.
  2. In the Open box, paste %systemroot%\syswow64\regedit , and then click OK.

Then do the following below as mentioned by Filip Savic and dayudodo:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem@LongPathsEnabled to 1
David Charles
  • 537
  • 6
  • 11
  • Thank you @David, I really needed to find a way in order to go through the selected answer by @Filip!! – Elias Oct 06 '20 at 14:06
12

I had the same error trying to install Jupyter, with the path under my user profile ending with \site-packages\pip-19.0.1.dist-info\METADATA

When I checked that location it didnt contain METADATA, but another folder named pip-19.0.1.dist-info That folder had several files in it including METADATA

I moved those files back the directory so it matched the path listed in the error and then upgraded pip (Under an administrator account)

pip3 install --upgrade pip

Which worked and updated pip

I could then run the Jupyter install and got no error

ah bon
  • 9,293
  • 12
  • 65
  • 148
Justin Cooksey
  • 311
  • 2
  • 5
6

So the above so called solution didn't make much sense to me.. Sorter path?? Anyways, what worked for me, is this.

My error:

Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'c:\\users\\MYUSERNAME\\appdata\\roaming\\python\\python37\\site-packages\\pip-19.0.1.dist-info\\METADATA'

So I went to the directory:

c:\\users\\MYUSERNAME\\appdata\\roaming\\python\\python37\\site-packages\\pip-19.0.1.dist-info\\   

Indeed there was no MetaData file. However there was a folder called 19.0.1.dist-info, inside that, has the meta data file. Just move it outside into the above directory, and BAM! Problem fixed.

Nino Filiu
  • 16,660
  • 11
  • 54
  • 84
EsC369
  • 97
  • 7
  • Copying the METADATA file from my pipxxx.dist-info folder into the requests-xx folder worked for me (After changing the max_path as suggested elsewhere which didn't work) – Wyse09 Feb 12 '22 at 03:36
6

I experienced this error while I was installing Apache Superset on Windows 10. The problem is with the MAX_PATH length.

pip on windows is not able to handle those long installation path url so it usually results in errors.

Solution: What worked for me was to Uninstall python then ReInstalled it again but this time after a successful reinstallation, you HAVE TO DISABLE THE PATH LENGTH LIMIT

Like on the highlighted region there.

Tadiwanashe
  • 1,246
  • 14
  • 15
5

The file path is to long, open a PowerShell prompt as an administrator and run:

Set-ItemProperty -Path "HKLM:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1
Jesper Hustad
  • 51
  • 1
  • 1
4

I had this problem while trying to install pytest on macOS

ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/Users/<USERNAME>/Projects/venvs/<VIRTUALENV_NAME>/lib/python3.8/site-packages/pytest-6.2.5.dist-info/METADATA

I navigated to the site-packages directory and deleted pytest-6.2.5.dist-info folder. Then try running the package installation command again.

tngeene
  • 370
  • 2
  • 7
3

Just ran into a similar problem with but with different versions. Similar to what EsCS69 said I just found the director and saw that there was no MetaData file. However I couldn't just pull it out from another file. So instead I justed deleted that folder and ran pip install --upgrade --force-reinstall tensorflow-gpuor pip install --upgrade --force-reinstall tensorflow if you aren't using the gpu version. Problem solved.

Will Mulcahey
  • 89
  • 1
  • 7
2

Windows 10

Windows limits locations paths with more than 260 characters. You should just enable that following this 4 steps!!!

  1. Click Window key and type gpedit. msc, then press the Enter key.
  2. Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem.
  3. Double click Enable NTFS long paths.
  4. Select Enabled, then click OK.
sam
  • 1,819
  • 1
  • 18
  • 30
1

You might not like this answer, but what worked for me was to find the file: "METADATA" from a folder with an older version and copy it into the newer one. This is not a solution I'm confident in, but pip at least finished installing.

Brad123
  • 877
  • 10
  • 10
1

Try deleting the package in envs/$env_name/Lib/site-packages

Tae Soo Kim
  • 1,019
  • 8
  • 14
1

I ended up deleting the whole directory and re-running "pip install ..." and that worked for me.

Oer
  • 447
  • 5
  • 8
1

Navigate to the folder \site-packages\ and delete the package folder you're trying to install.

Then launch Windows PowerShell (run as admin) and enter this command:

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

and try again.

Reza Rahemtola
  • 1,182
  • 7
  • 16
  • 30
CigarDon
  • 79
  • 1
  • 4
  • 14
0

Changing the Long install path value to 1 did NOT solve problem in my case. I have removed the local folder which is giving an error and installed the package again and it worked.

Following is the error I have seen: :ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'c:\users\user_name\appdata\local\continuum\anaconda3\lib\site-packages\numpy-1.20.1.dist-info\METADATA'

I removed the folder: "'c:\users\user_name\appdata\local\continuum\anaconda3\lib\site-packages\numpy-1.20.1.dist-info'

Inuganhu
  • 31
  • 4
0

For me what worked is running the same command 3 times. Don't know why, but it solved the issue.

First time enter image description here

Second Time enter image description here

Third time's a charm :) enter image description here

Shining Love Star
  • 5,734
  • 5
  • 39
  • 49
0

its very simple when we get this error, this case
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'c:\\users\\adrian\\appdata\\roaming\\python\\python37\\site-packages\\pip-19.0.1.dist-info\\METADATA' . what we need to do is delete that folder , in this case pip-19.0.1.dist-info ;

Problem solved

Prajot Kuvalekar
  • 5,128
  • 3
  • 21
  • 32
0

A simple pip upgrade did the trick for me.

Raghul Raj
  • 1,428
  • 9
  • 24
0

Well I got the similar error when I was trying to install tensorflow on windows: 10. I was able to solve this by opening the Powershell as an Adiminstrator an paste the following command and click [ENTER]

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

I got this solution here.

crispengari
  • 7,901
  • 7
  • 45
  • 53
0

I also had this no metadata error when I was trying to install anything, however I had the metadata.json fine in the requested directory. I simply removed .json extension and renamed file to METADATA.

I have macOS, so the LongPath was not the problem for me and I also could not afford to simply remove the envs directory with so many libraries installed there

Nadiia
  • 21
  • 1