You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 10下Python 3.7.4 pickle存aux开头文件报FileNotFoundError原因

Why Filenames Starting with "aux" Cause FileNotFoundError on Windows with Python

Hey there! Let's dig into why you're running into this frustrating FileNotFoundError when trying to save pickle files with names starting with aux on Windows 10. It's not a Python or pickle bug—this is a Windows system-level restriction rooted in legacy DOS naming rules.

The Root Cause: Windows' Reserved Device Names

Back in the DOS days, certain short names were reserved to refer to system devices (like serial ports, printers, or the null device). Windows kept this compatibility for backward compatibility, so even today, you can't use these names as file or folder names—even if you add an extension (like .pk or .foo).

aux is one of these reserved names. Other common ones include:

  • con (console input/output)
  • prn (printer)
  • nul (null device)
  • com1 to com9 (serial ports)
  • lpt1 to lpt9 (parallel ports)

When you try to open a file named aux.pk in Python, the Windows API doesn't treat it as a regular file—it thinks you're trying to access the legacy aux device, which doesn't exist as a file on your system. That's why you get a FileNotFoundError, even though you're trying to create a new file.

Your Test Cases Make Perfect Sense Now

Looking at your code examples:

  • All attempts using aux (with any extension, raw string, or formatted string) fail because Windows blocks the name entirely.
  • Switching to tux works because it's not a reserved device name—Windows treats it as a normal file, so pickle can save it without issues.

Quick Recap

This is purely a Windows compatibility quirk. Python's open() function relies on Windows' underlying file handling APIs, so it has to respect these old naming rules. The workaround you found (using a non-reserved filename) is the simplest and most reliable fix.

内容的提问来源于stack exchange,提问作者Alexandre Cavalcante

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:20:22