All about "Disable path length limit" in Python installation

All about Disable Path Length Limit during Python Installation on Windows

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.

Note: This article used Python 3.10.5 on Windows 10.
Note: Solutions shown here to disable "path length limit" require admin privileges.

When we install Python on Windows, the final step normally includes the option to "Disable path length limit" as shown below.

Python install successful - disable path length limit

The description below the option is self-explanatory:

Changes your machine configuration to allow programs, including Python to bypass the 260 character "MAX_PATH" limitation.

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.

Note: For additional information on this limitation see the Maximum Path Length Limitation MSDN article.

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:

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem

We can also use PowerShell to check the value of the LongPathsEnabled by running the following command:

Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled"

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.

Note: We are going to change the value of only one registry key, but to be on the safe side, you could backup the registry or create a restore point just in case.

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.
    Windows - search for regedit tool
  • Once inside the registry editor, copy the location shown below into the address bar and hit ENTER:
    Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem

    Windows regedit tool - Enter longpathsenabled location path

  • 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.
    Windows regedit tool - Select longpathsenabled registry key
  • 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".
    Windows regedit tool - Edit value for longpathsenabled registry key

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:

Cannot edit LongPathsEnabled: Error writing the value's new contents.

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:
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
    "LongPathsEnabled"=dword:00000001
  • Save the file with the .reg extension (for example, we could name it longpaths.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".
    Windows warning message after running file with .reg extension

Trying this without admin access

If we lack admin privileges, the pop-up window will show up with the following message:

Cannot import .... Not all data was successfully written to the registry. Some keys are open by the system or other processes, or you have insufficient privileges to perform this operation.

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.
    Windows PowerShell - Run as administrator
  • Once in PowerShell, copy and paste the following command and hit ENTER:
    New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
    -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
  • If everything was successful, we should see "LongPathsEnabled : 1" in the output message:
    PowerShell - Run new-itemproperty command to modify longpathsenabled registry key

Trying this without admin access

Without admin privileges, we get a bunch of messages in red, starting with this line:

New-ItemProperty : Requested registry access is not allowed.

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.

Tags:

Write a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.