权限错误:[Errno 13] 权限被拒绝:'emails2/Train'

3
我在stackoverflow和其他网站上搜索过,但仍然没有找到解决方案。我的问题是,我正在尝试访问包含“ ham”或“ spam”电子邮件的两个不同文件夹,以将其加入数据集进行模型训练。我似乎一直遇到权限错误,不确定如何通过Python或Windows资源管理器解决它。我想知道如何用多种方法解决这个问题,以便更好地理解它。
以下是代码:
ham = 'ham'
spam = 'spam'
data = 'emails2'
hamfiles = []
spamfiles = []

'''Searching File Path'''
print('# MESSAGE: Finding for files ----------------------------------------------------------------------------------')
for subdir, folders, files in os.walk(data):
    if subdir.__contains__(ham):
        # print(subdir)
        for file in files:
            # print(os.path.join(subdir, file))
            hamfiles.append(os.path.join(subdir, file))
    else:
        for file in files:
            # print(os.path.join(subdir, file))
            spamfiles.append(os.path.join(subdir, file))

import glob

X_file = []
y_class = []

eof = [('eof')]

for hamfile in hamfiles:
    # print(hamfile)
    files = glob.glob(hamfile)
    for file in files:
        # print(file)
        h = open(file, encoding='UTF8', errors='replace')
        buffer = h.read()

        '''Tokenize'''
        token = nltk.word_tokenize(buffer)
        '''Part Of Speech Tagging'''
        posTag = nltk.pos_tag(token)
        '''Append to Array'''
        for (word, tag) in posTag:
            X_file.append(word)
            y_class.append('ham')


for spamfile in spamfiles:
    # print(spamfile)
    files = glob.glob(spamfile)
    for file in files:
        # print(file)
        s = open(file, encoding='UTF8', errors='replace')
        buffer = s.read()

        '''Tokenize'''
        token = nltk.word_tokenize(buffer)
        '''Part Of Speech Tagging'''
        posTag = nltk.pos_tag(token)
        '''Append to Array'''
        for (word, tag) in posTag:
            X_file.append(word)
            y_class.append('spam')

print('# MESSAGE: Print X_ham ----------------------------------------------------------------------------------------')
print(X_file)
h.close()

def create_lexicon(X_file,y_class):

    lexicon = []
    with open(X_file,'r+') as f:
        contents = f.readlines()
        for l in contents[:hm_lines]:
            all_words = word_tokenize(l)
            lexicon += list(all_words)

    with open(y_class,'r+') as f:
        contents = f.readlines()
        for l in contents[:hm_lines]:
            all_words = word_tokenize(l)
            lexicon += list(all_words)

我了解这可能是一个Windows权限错误,但我以前从未遇到过这种情况。

1个回答

2

如果您是从命令提示符中运行Python文件,请右键单击打开命令提示符并选择以管理员身份运行。

如果您使用其他IDE(例如Spyder、PyCharm等),也请尝试以管理员身份运行。

还要确保Python脚本使用的文件没有被其他应用程序访问。

希望这可以帮助到您。


我怎样可以在没有管理员权限的情况下打开它? - PV8
1
如果您使用“以管理员身份运行”命令执行应用程序,则向系统通知您的应用程序是安全的,并且正在执行需要管理员权限的操作。只有在您确认的情况下,才能完成此操作,前提是您是管理员。 - ArunJose

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接