我打开了spyder,但它在启动时停止了。通过anaconda提示符启动spyder会显示问题。
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\user\\AppData\\Local\\Microsoft\\Windows\\Fonts\\codicon.ttf'
我将在第一部分中解释这个问题。如果您知道修复它的方法,那么您实际上不需要阅读第二部分。这可能很重要,我有:
Anaconda:
anaconda Command line client (version 1.12.1)
Windows 11 Home
Python 3.11
搜索SO后,我发现有人有类似的问题:How do you launch Spyder in Windows 11? 您也可以在那里找到完整的输出。我查了一下,除了文件名之外,对我来说几乎是一样的。如果你看看那里,你会找到一个答案,我的。但这是一个临时解决方案,每次打开spyder都需要完成。
我希望有人可以帮助解决问题,因为这是唯一的问题,而且没有任何答案。我还认为我可以使用下面提供的代码更清楚地描述问题(之前的代码是没有注释“我自己做了这个”的所有内容)
我用一个解决方法回答了这个问题:剪切文件并将其粘贴到其他位置。这样做将在其先前的位置安装另一个同名的文件。我必须执行此操作两次:对于 codicon.tff 和materialdesignicons6-webfont.ttf,使用不同的文件给出相同的错误。
我什至进入了shutil.py 文件并自己更改了代码,以编程方式执行此操作。然而,由于某种原因,这仍然需要我再次启动spyder,因为它在第一次启动后仍然会抛出以下错误:
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\user\\AppData\\Local\\Microsoft\\Windows\\Fonts\\codicon.ttf'
第二次启动spyder就不会出现这个错误了。通过启动spyder 3次来完成这项工作:
这是更改后的代码,在shutil.py中:
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
我自己写了异常PermissionError,这是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 无法启动并显示以下消息,
spyder PermissionError:[Errno 13]权限被拒绝: 'C:\Users\用户名\AppData\Local\Microsoft\Windows\Font