简体   繁体   English

在 python 中使用 os 库时,Windows 10 中的 Jupiter 笔记本出现权限错误 [Errno 13]

[英]Permission error in Jupiter notebook in Windows 10 while using os library in python [Errno 13]

The file of my jupyter notebook and the folder I have been trying to open are in the same folder.我的 jupyter notebook 的文件和我一直试图打开的文件夹在同一个文件夹中。

When running the following code (here, 'mbdataset' is the folder I am trying to open):运行以下代码时(此处,“mbdataset”是我要打开的文件夹):

hf= open('mbdataset','r')
hc= hf.read()
hc

I am getting the following error:我收到以下错误:

PermissionError: [Errno 13] Permission denied: 'mbdataset'

Please tell me what I should do to avoid this.请告诉我应该怎么做才能避免这种情况。

Is "mbdataset" the actual filename? “mbdataset”是实际的文件名吗?

Depending on how you start your notebook, you might want to do:根据您启动笔记本的方式,您可能需要执行以下操作:

import os
os.getcwd()

To check your current working directory.检查您当前的工作目录。 You can set your working directory with:您可以使用以下命令设置工作目录:

os.chdir(path_to_dataset)

As your comment says, you try to open a folder with open()正如您的评论所说,您尝试使用open()打开一个文件夹

open() expects a file. open()需要一个文件。 So depending on your dataset, you might need to iterate through files, or read a json, to says this, more information is needed.因此,根据您的数据集,您可能需要遍历文件,或读取 json,也就是说,需要更多信息。

For example, you could do this:例如,您可以这样做:

import glob
files = []
for file in glob.glob("/mbdataset/*.(txt for example)"):
    text = open(file, "r")
    files.apped(text.read())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jupyter Notebook 中的 Kernel 错误(Errno 13 Permission denied),Windows 10 - Kernel error (Errno 13 Permission denied) in Jupyter Notebook, Windows 10 权限错误Errno13-Windows上的Python - Permission Error Errno13 - Python on Windows PermissionError:[Errno 13] 导入 pandas 库时出现权限被拒绝错误 - PermissionError: [Errno 13] Permission denied error while importing pandas library Python Pillow 库错误:PermissionError:[Errno 13] 权限被拒绝 - Python Pillow Library Error : PermissionError: [Errno 13] Permission denied Python 操作系统:[Errno 13] 权限被拒绝 - Python os: [Errno 13] Permission Denied python paramiko在使用sftp的Windows服务器上给出错误“Permission denied [Errno 13]” - python paramiko giving error “Permission denied [Errno 13]” on windows server on using sftp PermissionError:[Errno 13] python jupyter notebook 中的权限被拒绝 - PermissionError: [Errno 13] Permission denied in python jupyter notebook PermissionError: [errno 13] 在 Windows 10 中运行 python 脚本时权限被拒绝 - PermissionError: [errno 13] permission denied when running python script in Windows 10 PermissionError: [Errno 13] 权限被拒绝 python 错误 - PermissionError: [Errno 13] Permission denied python error Errno 13 权限被拒绝 Python(使用 pyinstaller) - Errno 13 Permission denied Python (Using pyinstaller)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM