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

Spyder启动失败:字体文件PermissionError问题求助

问题:Spyder启动卡在初始化阶段,遭遇字体文件权限错误

启动Spyder时卡在初始化环节,通过Anaconda提示符启动时出现如下报错:

PermissionError: [Errno 13] Permission denied: 'C:\Users\user\AppData\Local\Microsoft\Windows\Fonts\codicon.ttf'

环境配置

  • Anaconda: anaconda命令行客户端(版本1.12.1)
  • Windows 11 Home
  • Python 3.11

临时解决方案

将codicon.ttf和materialdesignicons6-webfont.ttf这两个字体文件剪切到其他目录,系统会自动在原路径生成同名文件,但每次启动Spyder都需要重复执行该操作。

已尝试的自定义修复(未彻底解决)

修改了shutil.py中的copyfile函数,添加了PermissionError的处理逻辑,同时编写了create_folder_for_special_files函数自动迁移字体文件,但仍需三次启动Spyder才能成功:第一次触发codicon.ttf报错并处理,第二次触发materialdesignicons6-webfont.ttf报错并处理,第三次才能正常启动。

修改后的copyfile函数代码

def copyfile(src, dst, *, follow_symlinks=True):
    """Copy data from src to dst in the most efficient way possible.

    If follow_symlinks is not set and src is a symbolic link, a new
    symlink will be created instead of copying the file it points to.

    """
    sys.audit("shutil.copyfile", src, dst)

    if _samefile(src, dst):
        raise SameFileError("{!r} and {!r} are the same file".format(src, dst))

    file_size = 0
    for i, fn in enumerate([src, dst]):
        try:
            st = _stat(fn)
        except OSError:
            # File most likely does not exist
            pass
        else:
            # XXX What about other special files? (sockets, devices...)
            if stat.S_ISFIFO(st.st_mode):
                fn = fn.path if isinstance(fn, os.DirEntry) else fn
                raise SpecialFileError("`%s` is a named pipe" % fn)
            if _WINDOWS and i == 0:
                file_size = st.st_size

    if not follow_symlinks and _islink(src):
        os.symlink(os.readlink(src), dst)
    else:
        with open(src, 'rb') as fsrc:
            try:
                with open(dst, 'wb') as fdst:
                    # macOS
                    if _HAS_FCOPYFILE:
                        try:
                            _fastcopy_fcopyfile(fsrc, fdst, posix._COPYFILE_DATA)
                            return dst
                        except _GiveupOnFastCopy:
                            pass
                    # Linux
                    elif _USE_CP_SENDFILE:
                        try:
                            _fastcopy_sendfile(fsrc, fdst)
                            return dst
                        except _GiveupOnFastCopy:
                            pass
                    # Windows, see:
                    # https://github.com/python/cpython/pull/7160#discussion_r195405230
                    elif _WINDOWS and file_size > 0:
                        _copyfileobj_readinto(fsrc, fdst, min(file_size, COPY_BUFSIZE))
                        return dst

                    copyfileobj(fsrc, fdst)

            # Issue 43219, raise a less confusing exception
            except IsADirectoryError as e:
                if not os.path.exists(dst):
                    raise FileNotFoundError(f'Directory does not exist: {dst}') from e
                else:
                    raise
                    
            # Handle PermissionError, I made this one myself
            except PermissionError:
                # Check if the file name matches
                special_files = ["codicon.ttf", "materialdesignicons6-webfont.ttf"]
                if os.path.basename(dst) in special_files:
                    new_dst = create_folder_for_special_files(dst)
                    return new_dst  # Returning the new path after moving the file
    
                # Raise the original PermissionError if the file doesn't match
                raise

    return dst

create_folder_for_special_files函数代码

from datetime import datetime
import shutil
def create_folder_for_special_files(dst):
    #I made this one myself
    today_date = datetime.now().strftime("%Y-%m-%d")
    new_folder_path = os.path.join("C:\Users\user\Documents\fontstuff", today_date)
    os.makedirs(new_folder_path, exist_ok=True)
    shutil.move(dst, os.path.join(new_folder_path, os.path.basename(dst)))
    return os.path.join(new_folder_path, os.path.basename(dst))

寻求永久解决方法

需要找到能彻底解决该字体文件权限问题的方案,无需每次启动Spyder重复操作或多次启动才能进入程序。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 01:22:04