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

使用Scanpy在Jupyter Notebook中打开文件遇PermissionError求助

问题描述

在Jupyter Notebook中使用Scanpy读取文件时触发PermissionError(权限拒绝错误),无法访问路径G:\scanpy data\extracted\GSM5226574_C51ctr_raw_counts.csv。已尝试用双斜杠处理路径,但问题仍未解决。报错堆栈信息如下:

PermissionError                           Traceback (most recent call last)
Cell In[17], line 1
----> 1 sc.read_csv('G:\scanpy data\extracted\GSM5226574_C51ctr_raw_counts.csv').T

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\anndata_io\read.py:54, in read_csv(filename, delimiter, first_column_names, dtype)
30 def read_csv(
31     filename: Union[PathLike, Iterator[str]],
32     delimiter: Optional[str] = ",",
33     first_column_names: Optional[bool] = None,
34     dtype: str = "float32",
35 ) -> AnnData:
36     """
37     Read <code>.csv</code> file.
38
(...)
52         Numpy data type.
53     """
--- > 54     return read_text(filename, delimiter, first_column_names, dtype)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\anndata_io\read.py:358, in read_text(filename, delimiter, first_column_names, dtype)
356         return _read_text(f, delimiter, first_column_names, dtype)
357 else:
-- > 358     with filename.open() as f:
359         return _read_text(f, delimiter, first_column_names, dtype)

File ~\AppData\Local\Programs\Python\Python310\lib\pathlib.py:1117, in Path.open(self, mode, buffering, encoding, errors, newline)
1115 if "b" not in mode:
1116     encoding = io.text_encoding(encoding)
-- > 1117 return self._accessor.open(self, mode, buffering, encoding, errors,
1118                            newline)

PermissionError: [Errno 13] Permission denied: 'G:\scanpy data\extracted\GSM5226574_C51ctr_raw_counts.csv'
解决方法
  • 检查文件权限:右键目标CSV文件 → 属性 → 安全选项卡,确认当前用户拥有读取权限。若没有,点击“编辑”添加用户并勾选读取权限。
  • 正确处理路径转义:Windows路径可使用原始字符串(路径前加r)避免转义字符干扰,代码示例:
    sc.read_csv(r'G:\scanpy data\extracted\GSM5226574_C51ctr_raw_counts.csv').T
    
  • 关闭占用文件的程序:如果文件正在被Excel、记事本等程序打开,会导致Python无法读取,先关闭这些程序再重试。
  • 以管理员身份运行Jupyter:右键Jupyter Notebook快捷方式 → 以管理员身份运行,提升权限后尝试读取文件。
  • 转移文件到无限制目录:将CSV文件复制到D:\temp这类普通目录,修改路径后读取,示例:
    sc.read_csv(r'D:\temp\GSM5226574_C51ctr_raw_counts.csv').T
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 17:53:11