Skip to content

Instantly share code, notes, and snippets.

@rndazurescript
Created March 13, 2020 10:18
Show Gist options
  • Save rndazurescript/06ff59abfbec061c482734c22d8387d9 to your computer and use it in GitHub Desktop.
Save rndazurescript/06ff59abfbec061c482734c22d8387d9 to your computer and use it in GitHub Desktop.
Enable long paths on windows

On Windows, you may encounter the error, "Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory:" followed by a long pathname to a file like sharded_mutable_dense_hashtable.cpython-37.pyc. Typically, this error happens because the depth of the folder path becomes too long. In this case, set the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem@LongPathsEnabled to 1 to enable long paths. Alternately, check where your Python interpreter is installed. If that location has a long path, try reinstalling in a folder with a shorter path.

Ref: https://docs.microsoft.com/en-us/azure/azure-functions/functions-machine-learning-tensorflow?tabs=cmd

$registryPath = "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem"
$Name = "LongPathsEnabled"
$expectedValue = "1"
$currentValue=(Get-ItemProperty -Path $registryPath -Name $Name).$Name
if ($currentValue -ne $expectedValue){
Write-Host "Enabling long path support"
New-ItemProperty -Path $registryPath -Name $name -Value $expectedValue -PropertyType DWORD -Force | Out-Null
}
else{
Write-Host "Long path support already activated"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment