When we go through the Python installation steps on the Windows system, one of the steps asks us if we want to Disable path length limit. So what is it and should you disable it? What do you do if you forgot to disable it after installation? This step might also not show up at all. In this tutorial, we are going to learn why is this option sometimes skipped during the installation and how to enable it once Python has already been installed.
When we install Python on Windows, the final step normally includes the option to "Disable path length limit" as shown below.
The description below the option is self-explanatory:
Clicking on it will remove the Windows filesystem limitation of 260 characters for paths that include folder path with the filename and its extension, so exceeding this limitation is possible.
Disabling the path limitation from the installation step is straightforward. Sometimes though, this step might be missing during the Python installation. So, why does that happen?
If the "Disable path length limit" step is missing
If you are running a version of Windows older than Windows 10, you most likely won't see the above installation step at all and you will be limited to the path length of 260 characters.
On the other hand, if your installation skipped the Disable path length limit step and you are using Windows 10 or later, it is likely that this path limit is already disabled.
Checking if "path length limit" is already disabled
To determine whether or not the path length limit is already disabled, we can use the regedit tool to check the value of the registry key LongPathsEnabled located at the location here:
We can also use PowerShell to check the value of the LongPathsEnabled by running the following command:
The path length limit is disabled if the value is 1.
Forgetting to disable the path length limit during installation
What can we do when we were shown the option to "Disable path length limit" during the Python installation but forgot to enable it? Even though we can modify the Python setup (Settings > Apps > Apps & features, then search for python and click on "Modify" button), there is no option to Disable path length limit.
One solution is to reinstall Python and make sure to "Disable path length limit" during the last installation step.
To fix this issue without reinstalling Python we need to change the value of the registry key LongPathsEnabled mentioned earlier. That is what we will do next.
Disabling the path length limit manually
As stated at the beginning of the tutorial, we need admin privileges to modify this registry key. Doing this using regular user privileges won't work.
We need to set the value to 1 for the LongPathsEnabled registry key and there are several ways to do this.
Method 1 - Change the LongPathsEnabled key using regedit
One way is to use Registry Editor "regedit" tool. If you are not familiar with using this tool, it might be better to try one of the other methods such as using the .reg file or using PowerShell.
The steps to modify the value for the LongPathsEnabled registry key using Registry Editor is as follows:
- On Windows, search for regedit, select "Registry Editor" and run it.
- Once inside the registry editor, copy the location shown below into the address bar and hit ENTER:
- You should now jump to that location and see various registry keys that exist there. Find the LongPathsEnabled registry key and double-click on it.
- Pop-up windows will open in which we can edit the value of the registry key.
Under "Value name" make sure it shows LongPathsEnabled as you don't want to change a value for the wrong registry key!!! Under "Value data", change the value from 0 to 1 and click "OK".
The LongPathsEnabled registry key should now show the value 1.
Trying this without admin access
Running as a regular user without admin privileges, we get the "Error Editing Value" error:
Method 2 - Create and run the .reg file
With this method, we create a .reg
file that will modify the same registry key without using the Regedit tool. The steps to do that are:
- Open a text editor and create a new file.
- Copy and paste the following code:
- Save the file with the
.reg
extension (for example, we could name itlongpaths.reg
). - Open the File Explorer and double-click the file to run it. Windows will recognize the
.reg
extension and try to modify the LongPathsEnabled registry key. - However, before making any changes, it will ask you if you are sure you want to proceed. Select "Yes".
Trying this without admin access
If we lack admin privileges, the pop-up window will show up with the following message:
Method 3 - Run the command in PowerShell
We can accomplish the same with PowerShell by following these steps:
- On Windows, search for powershell, right-click on Windows PowerShell, select "Run as Administrator" from the menu and run it.
- Once in PowerShell, copy and paste the following command and hit ENTER:
- If everything was successful, we should see "LongPathsEnabled : 1" in the output message:
Trying this without admin access
Without admin privileges, we get a bunch of messages in red, starting with this line:
Conclusion
During Python installation, there is a step to "Disable path length limit". This option is also not always available. Or perhaps it was available but we forgot to disable it. In either case, to disable the path length limit, we can repeat the Python installation or we can set a value of 1 for the LongPathsEnabled registry key manually. In both cases though, we need admin privileges to remove this path limitation.