[英]LongPathsEnabled feature doesn't seem to work
The initial trouble I encountered was the pip
failing to install tensorflow
lib due to Windows MAX_PATH
restriction of 260 characters.我遇到的最初问题是由于 Windows
MAX_PATH
限制为 260 个字符, pip
无法安装tensorflow
lib。 Here's the message I received:这是我收到的消息:
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory:
'C:\\Users\\Root\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\
local-packages\\Python39\\site-packages\\tensorflow\\include\\external\\com_github_grpc_grpc\\
src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\client_load_reporting_filter.h'
HINT: This error might have occurred since this system does not have Windows Long Path support enabled.
You can find information on how to enable this at https://pip.pypa.io/warnings/enable-long-paths
I looked up the hint page that pip
suggested.我查看了
pip
建议的提示页面。 This linked to the Microsoft docs page which explained that the restriction could be lifted via setting the REG_DWORD
registry key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\FileSystem\\LongPathsEnabled
to 1
.这链接到 Microsoft 文档页面,该页面解释了可以通过将
REG_DWORD
注册表项HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\FileSystem\\LongPathsEnabled
为1
来解除限制。
After the amendment I made to the registry key, I rebooted the system and tried to install the tensorflow
again.在我对注册表项进行修改后,我重新启动系统并尝试再次安装
tensorflow
。 It didn't work - I received the same error message.它没有用 - 我收到了同样的错误信息。 Then I got back to the Microsoft docs page and discovered that
LongPathsEnabled
option could also be activated via Group Policy editor (aka gpedit.msc
).然后我回到 Microsoft 文档页面,发现
LongPathsEnabled
选项也可以通过组策略编辑器(又名gpedit.msc
)激活。 There I went straight to Computer Configuration > Administrative Templates > System > Filesystem > Enable Win32 long paths
and set the policy to be Enabled
(it was Not Configured
initially, despite the registry key being set).在那里,我直接进入
Computer Configuration > Administrative Templates > System > Filesystem > Enable Win32 long paths
并将策略设置为Enabled
(尽管设置了注册表项,但最初Not Configured
)。 Then I rebooted my PC again, opened cmd
and typed pip install tensorflow
once again.然后我再次重新启动我的电脑,打开
cmd
并再次输入pip install tensorflow
。 Got the same error message.得到同样的错误信息。
This is where things started to get interesting: I was able to find out that LongPathsEnables
option doesn't seem to work on my PC at all.这就是事情开始变得有趣的地方:我发现
LongPathsEnables
选项似乎在我的 PC 上根本不起作用。 Here's what Microsoft docs say:以下是 Microsoft 文档所说的:
These are the file management functions that no longer have MAX_PATH restrictions if you opt-in to long path behavior: CopyFileW, CopyFile2, CopyFileExW, CreateFileW, CreateFile2 ...
如果您选择加入长路径行为,则这些文件管理功能不再具有 MAX_PATH 限制:CopyFileW、CopyFile2、CopyFileExW、CreateFileW、 CreateFile2 ...
So I opened Visual Studio and wrote this code:所以我打开了 Visual Studio 并编写了以下代码:
int main(int argc, char ** argv)
{
HANDLE fileHandle = CreateFile2(
L"C:\\Users\\Root\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\tensorflow\\include\\external\\com_github_grpc_grpc\\src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\client_load_reporting_filter.h",
GENERIC_ALL,
0,
CREATE_ALWAYS,
NULL
);
if (fileHandle == INVALID_HANDLE_VALUE)
{
DWORD error = GetLastError();
cout << "CreateFile2 failed with LastError code: " << error << endl;
}
else
{
cout << "Success" << endl;
}
getchar();
return 0;
}
And this failed with GetLastError()
code 3 ( ERROR_PATH_NOT_FOUND
- The system cannot find the path specified).这失败了
GetLastError()
代码 3 ( ERROR_PATH_NOT_FOUND
- 系统找不到指定的路径)。 It is to be noted that when I shortened the path to C:\\\\Users\\\\Root\\\\AppData\\\\Local\\\\Packages\\\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\\\LocalCache\\\\local-packages\\\\Python39\\\\site-packages\\\\tensorflow\\\\include\\\\external\\\\com_github_grpc_grpc\\\\src\\\\core\\\\ext\\\\filters\\\\client_channel\\\\client_load_reporting_filter.h
which resulted in 252 characters long path, it succeeded so I deduced that CreateFile2
also doesn't seem to have identified LongPathsEnabled
option being set.需要注意的是,当我将路径缩短为
C:\\\\Users\\\\Root\\\\AppData\\\\Local\\\\Packages\\\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\\\LocalCache\\\\local-packages\\\\Python39\\\\site-packages\\\\tensorflow\\\\include\\\\external\\\\com_github_grpc_grpc\\\\src\\\\core\\\\ext\\\\filters\\\\client_channel\\\\client_load_reporting_filter.h
这导致了 252 个字符的长路径,它成功了,所以我推断出CreateFile2
似乎也没有确定正在设置的LongPathsEnabled
选项。 The cause of the issue with the C++ program might be that there should be a longPathsAware
element set to true
in its application manifest (this is stated in the same Microsoft docs page I've referred to above), but I don't have a clue on how to set this option since it should have worked right after setting the registry key and rebooting my PC. C++ 程序问题的原因可能是它的应用程序清单中应该有一个
longPathsAware
元素设置为true
(这在我上面提到的同一个 Microsoft 文档页面中进行了说明),但我没有关于如何设置此选项的线索,因为它应该在设置注册表项并重新启动我的 PC 后立即起作用。 I recall that I experienced the same issue about a half year ago on my previous Windows 10 installation and it got fixed super easily - LongPathsEnabled
set to 1
, PC rebooted and pip install <some-package>
succeeded.我记得我大约半年前在我之前的 Windows 10 安装中遇到了同样的问题,并且它非常容易地修复 -
LongPathsEnabled
设置为1
,PC 重新启动并且pip install <some-package>
成功。 This answer: Filename too long in Git for Windows implies that some programs have the Long Paths feature disabled by default but I have no idea if this is the case and even if it is, how to set this for pip
.这个答案: 适用于 Windows 的 Git 中的文件名太长意味着某些程序默认禁用了长路径功能,但我不知道是否是这种情况,即使是这样,如何为
pip
设置它。 By the way, pip config set <name> <value>
failed due to pip.ini
file being inaccessible for writing (opened in PID: 0
).顺便说一下,
pip config set <name> <value>
失败,因为pip.ini
文件无法写入(在PID: 0
打开)。
Tried manually create the file ( client_load_reporting_filter.h
), copying the original contents from the internet and it didn't help either.尝试手动创建文件(
client_load_reporting_filter.h
),从互联网复制原始内容,但也没有帮助。 When I opened it in my notepad++
, the path string was C:\\Users\\Root\\AppData\\Local\\Packages\\PYTHON~1.9_Q\\LOCALC~1\\LOCAL-~1\\Python39\\SITE-P~1\\TE1A26~1\\include\\external\\COM_GI~1\\src\\core\\ext\\filters\\CLIENT~1\\LB_POL~1\\grpclb\\CLIENT~1.H
so notepad++
also seems to be unable to work with Long Paths.当我在
notepad++
打开它时,路径字符串是C:\\Users\\Root\\AppData\\Local\\Packages\\PYTHON~1.9_Q\\LOCALC~1\\LOCAL-~1\\Python39\\SITE-P~1\\TE1A26~1\\include\\external\\COM_GI~1\\src\\core\\ext\\filters\\CLIENT~1\\LB_POL~1\\grpclb\\CLIENT~1.H
所以notepad++
似乎也无法使用长路径。
I am completely clueless and desperate right now so I decided to ask a question here hoping that somebody have experienced this and might be able to help.我现在完全无能为力和绝望,所以我决定在这里问一个问题,希望有人经历过这种情况并且可以提供帮助。 I'll be happy if the issue can be resolved without reinstalling Windows, but this all seems so weird.
如果可以在不重新安装 Windows 的情况下解决问题,我会很高兴,但这一切似乎都很奇怪。
Okay guys I have solved the problem with tensorflow installation by downgrading Python to version 3.7.好的,我已经通过将 Python 降级到 3.7 版解决了安装 tensorflow 的问题。 But the issue with
CreateFile2
is still there so this part of my question is left unanswered.但是
CreateFile2
的问题仍然存在,所以我的这部分问题没有得到解答。
Thanks to Ryan Pepper , who clarified the situation a little by mentioning the fact that many programs still do not properly support Windows Long Paths.感谢Ryan Pepper ,他通过提到许多程序仍然不能正确支持 Windows Long Paths 的事实稍微澄清了情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.