Solving Error – Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory \\METADATA

Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory \\METADATA is an error which occurs in Python when the path is too long.

In this article we are going to explain why the error is popping up and show you how to solve the error and get rid of it for good.

Exploring the Error : Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory \\METADATA

First of all, after you reproduce the error. Check if your error message is like the error message bellow..

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

If that is the case, do not worry, we have many solutions to this error.

Bellow I will present multiple solutions some have worked for me and others have worked for other developers.

Solution 1 : Get rid of the 260 Character Path Limit

First of all, on windows go to the search at the bottom and type Registry editor then click on the icon.

Look for FileSystem and loof for LongPathsEnabled then change its value to 1.

You can find it in the regedit path bellow. After you finish restart your machine.

                                                                       #
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
                                                                       #

This should be enough to remove your error. But if that is not the case, try the solution bellow.

Solution 2 : Choose a folder with a shorter install path

The issue is that the name of the folder of the install path is long. That is why we edit the registry in the example above. Another way to deal with this is to choose the install folder with the shortest name and shortest path.

For example something like.

                                                                       #
C:/packages/mypackage
                                                                       #

If this is not enough, try the solution bellow.

Solution 3 : Move the last folder

If that does not work, please try this solution

Navigate to the path in your error message.

For example, this path.

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

Move the last folder pip-19.0.1.dist-info outside. And the error should be gone.

This error could be confusing at first. But once you understand why it is happening, it is easy to solve by only using a more recent method that works and achieves the same function.

Summing-up

I hope this article helped you solve the error, If not, I hope the solutions presented here guided you at least in the right direction. Keep coding and cheers, see you in another article. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/